in reply to seek in a text file
Update: Code:
#!/bin/perl -w use strict; my $file="dogy"; open(FH, "+<$file"); flock(FH, 2); my @newEntries; while(my $line = <FH>) { chomp($line); if ($line%2==1) { next; } push(@newEntries,$line); } seek FH,0,0; foreach my $ent (@newEntries) { print FH $ent . "\n"; } truncate FH, tell FH; close(FH)
Update: Even better?
#!/bin/perl -w use strict; my $file="dogy"; open(FH, "+<$file"); flock(FH, 2); my @newEntries; while(my $line = <FH>) { chomp($line); if ($line%2==1) { next; } push(@newEntries,$line); } seek FH,0,0; truncate FH, 0; foreach my $ent (@newEntries) { print FH $ent . "\n"; } close(FH)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: seek in a text file
by jwkrahn (Abbot) on Oct 06, 2008 at 04:45 UTC | |
|
Re^2: seek in a text file
by catfood (Novice) on Oct 06, 2008 at 01:18 UTC |