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

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.
  • Comment on Re^3: splitting a sequence using unpack

Replies are listed 'Best First'.
Re^4: splitting a sequence using unpack
by BrowserUk (Patriarch) on Mar 01, 2005 at 12:47 UTC

    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.

        True, but I habitually have $\ set to \n, the snippet I posted prints 3 chars per line, not a single long line as both your's would do.

        I didn't think of it being an optimisation either. Just when I want to print a substring of a string, I tend to think of substr.


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.