in reply to How do I modify a line within the file itself?
As others have already explained, you have to write the data back to the file, either by using in-place editing or just manually doing it yourself:
Or using something like Tie::File if your memory constraints are not preventing you:use strict; use warnings; my $file = shift; open FILE, $file or die "Can't read from $file!\n"; my @lines; while (my $line = <FILE>) { if ($line =~ /\>/) { push @lines, (split( /\s/, $line ))[0] . "\n"; } else { push @lines, $line; } } close FILE; open FILE, '>', $file or die "Can't write to $file!\n"; print FILE @lines; close FILE;
use strict; use warnings; use Tie::File; my $file = shift; tie my @lines, 'Tie::File', $file or die "Can't read from $file\n"; for (0 .. $#lines) { if ($lines[$_] =~ /\>/) { $lines[$_] = (split( /\s/, $lines[$_] ))[0] . "\n"; } }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|