Skip to content

Instantly share code, notes, and snippets.

@AndrewRussellHayes
Last active October 21, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRussellHayes/809d23bc56332486b251 to your computer and use it in GitHub Desktop.
Save AndrewRussellHayes/809d23bc56332486b251 to your computer and use it in GitHub Desktop.
file I/O best practices
my $filename = 'data.txt';
if (open(my $in, '<', $filename)) {
while (my $row = <$in>) {
chomp $row;
print "$row\n";
}
} else {
warn "Could not open file '$filename' $!";
}
my $filename = 'data.txt';
if (open(my $out, '>', $filename)) {
while (my $row = <$out>) {
chomp $row;
print "$row\n";
}
} else {
warn "Could not open file '$filename' $!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment