Skip to content

Instantly share code, notes, and snippets.

@shang-lin
Last active October 10, 2015 20:08
Show Gist options
  • Save shang-lin/3744600 to your computer and use it in GitHub Desktop.
Save shang-lin/3744600 to your computer and use it in GitHub Desktop.
Perl by Example
# Demo of how to process files in Perl.
# Replace with the actual name of the file.
my $file_name = "myfile.txt";
# Open the input file read-only.
open(IN, "<$file_name") or die "Cannot open $file_name\n";
# Open the output file for writing.
open(OUT, ">outputfile.txt") or die "Cannot open output file\n";
# Read the file line-by-line.
while (my $line = <IN>) {
# Write the line to the output file.
print OUT $line;
# If you want to remove the end-of-line character, use chomp.
# chomp $line;
}
# Close the file handles.
close IN;
close OUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment