in reply to Using File::ReadBackwards or equivalent on pre-existing file handle
#!/usr/bin/perl use warnings; use strict; my @positions; open my $OUT, '+>', '2.out' or die $!; for my $i (1 .. 20) { unshift @positions, tell $OUT; print {$OUT} "line $i\n"; } open my $BACK, '>', '2.back' or die $!; for my $pos (@positions) { seek $OUT, $pos, 0; my $line = <$OUT>; print {$BACK} $line; }
Update: Used the +> mode to keep the filehandle open.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using File::ReadBackwards or equivalent on pre-existing file handle
by HYanWong (Acolyte) on Jun 25, 2014 at 23:00 UTC |