without IO:All:
With IO::All:use File::Spec; my $file = File::Spec->catfile('my','dir','my_file.txt'); open (MYFILE, '<', $file) or die "Can't open $file: $!\n"; my @lines = <MYFILE>; close MYFILE; my $rfile = File::Spec->catfile('my','dir','reversed.txt'); open(RFILE, '>', $rfile) or die "Can't open $rfile: $!\n"; print RFILE reverse @lines; close RFILE;
To my mind the best thing about IO:All is that it takes care of all the error checking related to IO operations as well is the fussiness of opening and closing files in the correct mode for the desired operations.use IO::All; io->catdir('my','dir','my_file.txt')->backwards > io->catdir('my','dir','reversed.txt');
There are a number of other examples of how this module can be used to make your code simpler and more straightforward in the documentation that comes with IO::All.
update: I misspoke in the opening paragaraph. This example reverses the lines in the file, the whole text is not reversed.
--DrWhy
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
In reply to Re: IO::All is sliced bread
by DrWhy
in thread IO::All is sliced bread
by DrWhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |