in reply to Re^2: How to amend character count.
in thread How to amend character count.

Hello AnomalousMonk,

No worries no problems, I am always open to read comments from monks which have greater knowledge.

I am just commending to avoid confusion, OP on the open function has write mode > instead of read mode <.

Regarding:

I think that Peter Keystrokes wants to specify the input file on the command line, e.g.

OP defined a file my $filename = 'counts.txt';, so I assumed that he is defining the file through the script not through the command line. But never the less I was not aware of Using the magic ARGV handle - <> in perlop. as anonymous point out. Thanks for the tip. :)

Regarding:

This loop counts 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.)

I know some how that my results is wrong but I still can not understand why I can not link the lines that start with >hsa and why it only captures the ATG.... Can you provide me a bit more information? (Thanks in advance for your time and effort)

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^4: How to amend character count.
by Laurent_R (Canon) on May 06, 2017 at 21:43 UTC
    I am just commending to avoid confusion, OP on the open function has write mode > instead of read mode <.
    Because the OP opens this file with the intent of writing data to it, as shown in this code line:
    print $fh $count;
    So there is really nothing wrong with that.

    The OP code is reading from a file (passed as an argument to the program) and writing to another, opened explicitly with the open command.

      Hello Laurent_R,

      You are absolutely right. I was not aware of the (Variables related to filehandles):

      $ARGV Contains the name of the current file when reading from <> .

      Thanks again for clarification.

      Seeking for Perl wisdom...on the process of learning...not there...yet!
Re^4: How to amend character count.
by Anonymous Monk on May 06, 2017 at 20:49 UTC
    I still can not understand why I can not link the lines that start with >hsa and why it only captures the ATG.

    while (my $line = <>){ reads the line with the >hsa and then $line = <>; reads the next line.

      Hello Anonymous Monk,

      I finally got it, thank you for the explanation it is more clear now.

      I will update my answer just for personal future reference.

      Seeking for Perl wisdom...on the process of learning...not there...yet!