Hi thanos1983. Some comments on your post which I hope may avoid future confusion.

You have open (my $fh, '>', $filename) or die "Could not open '$filename' $!";. From the open documentation ...

Except for the use of  $filename in the OPed code instead of repeated literal strings (which I think is good practice in the interest of DRYness) and the inclusion of the mode in the error message, the OPed code is essentially the same as the documented examples. I don't understand the point you want to make.

Also on your while loop you have while (my $line = <>){ without the file handler.

I think that Peter Keystrokes wants to specify the input file on the command line, e.g.
    perl script.pl input.file
IOW, to read and write to separate files rather than appending to the input file as your final code example does | both your code examples do.

while (<$fh>) { chomp; if ($_ =~ /^>hsa/) { $count .= length $_; $count .= " "; } }
Update:
for (@lines) { print $fh length($_) . " " if ($_ =~ /^>hsa/); }

This loop counts | These loops count the characters in the lines beginning  '>hsa' rather than in the single string of the  'ACTG...' line that follows. The counts of 49 and 54 characters, respectively, for the two example data records reflect this. (And again, these counts are appended to the end of the input file rather than written to a separate file.)

Please believe that these comments are not meant to "pile on," but are only offered in the hope of smoothing the way a bit for future Seekers of Perl Wisdom.


Give a man a fish:  <%-{-{-{-<


In reply to Re^2: How to amend character count. by AnomalousMonk
in thread How to amend character count. by Peter Keystrokes

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.