in reply to Re: splitting a sequence using unpack
in thread splitting a sequence using unpack

...it does but has a disadvantage that the string must be stored twice in memory...

Would you explain this please?


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
  • Comment on Re^2: splitting a sequence using unpack

Replies are listed 'Best First'.
Re^3: splitting a sequence using unpack
by Taulmarill (Deacon) on Mar 01, 2005 at 12:33 UTC
    the string is originaly in $seq and is dublicated into the array @triplets. if you only want to print them, it's unnecessary to hold all triplets in memory but you can go through them one by one. besides that, storing triplets in an array should imho use more memory than the string stored in a scalar.

      Okay. That makes sense if all you want to do is print them out. I'd probably tackle it with substr in that case though.

      $p=0; print( substr $s, $p, 3 ), $p+=3 while $p < length $s;

      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.
        If all I wanted to do was printing them out, I'd do:
        print $s;
        Or, considering what I want to print was stored in a file, I'd skip the perl part, and do:
        cat file
        I mean, if I were to optimize this snippets for some limited functionality, I might as well do the optimization right.