in reply to Re^2: How do I move two lines up in a file using perl
in thread How do I move two lines up in a file using perl
Update: Also note that the offset can be negative releative to the current file position, see seek.use strict; use warnings; open (my $fh, '<', '/usr/share/dict/words') or die "Unable to open wor +ds: $!"; while (1) { my $line = <$fh>; if ( $line =~ /^M....$/) { my $pos = tell($fh) - length($line); chomp $line; print "$line found\n"; # Go back to beginning of file (rewind) seek ($fh,0,0); # Now go and read that record again seek ($fh, $pos, 0); $line = <$fh>; chomp $line; print "$line found again!\n"; last; } } close ($fh);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How do I move two lines up in a file using perl
by 7stud (Deacon) on Mar 17, 2010 at 09:29 UTC |