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:

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;

Or using something like Tie::File if your memory constraints are not preventing you:

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)

In reply to Re: How do I modify a line within the file itself? by jeffa
in thread How do I modify a line within the file itself? by newbie4659

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.