Last active
October 10, 2015 20:08
-
-
Save shang-lin/3744600 to your computer and use it in GitHub Desktop.
Perl by Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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