in reply to Re: simple but stuck
in thread Base sequence length in fasta format file

s/chomp;//;

You probably don't want to chomp, or all the printed bases will come out on the same line...
--
Mike

Replies are listed 'Best First'.
Re: Skip chomp?
by andye (Curate) on Apr 25, 2002 at 15:05 UTC
    RMGir, you have a good point.
    while (<INPUT>) { print if length($_) > 251; }

    lolly, note that the number has changed to 251 (250 for the number of bases, plus one for the newline).

    Andy.

    Update: Or of course:

    while (<INPUT>) { chomp; print $_."\n" if length($_) > 250; }
      Lets hope she doesnt have to run this code on a MS machine. Or one of the other machines where $/ is longer than 1 char. Or have it run on multiple systems simultaneously.

      No the safest way is to use chomp and remove the char. Then determine the length, then put the newline back on for printing.

      :-)

      Yves / DeMerphq
      ---
      Is $/ the same length on every system?

Re: Skip chomp?
by demerphq (Chancellor) on Apr 25, 2002 at 15:06 UTC
    Actually if portability is a concern than the chomp is vital, but no matter what hes going to have to factor the length of the /n into his length calculation.

    You are correct however in that he needs to put the newline back on once its been removed.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      NL len isn't going to be an issue, as long as he doesn't binmode the filehandle.

      CRLF pairs will be translated to a single LF on input, and translated back going the other way.

      But if you prefer to chomp then add the newline, that works too :)
      --
      Mike

        Er. Well a couple of test prove you right.

        But also prove me right: (phew ;-)

        print length <DATA>,$\; print length <DATA>,$\; __DATA__ ABCDEF ABCDEF
        outputs:
        7 6
        So there still could be an issue here... :-)

        Although granted it isnt the one I was harping on about...

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.