in reply to Reversing A File

How much memory do you have at your disposal?
my @input = <STDIN>; my $i = $#input; while ($i >= 0) { print $input[$i--]; }
Note that if you want to use less memory, you could split the file into chunks, reverse the chunks and then reverse-concatenate the chunks.

Replies are listed 'Best First'.
Re^2: Reversing A File
by camelcom (Sexton) on Dec 12, 2007 at 14:06 UTC
    As it's pure perl, I installed File::ReadBackwards locally and it's definitely the way to go - very impressive - only 90seconds to reverse the 180MB file and uses less than 5MB of memory to do it.

    I diff'd the original .txt file with the .rev.rev file and no differences, so it seems to work ok!

    problem solved - once again - many many thanks!