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

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.

Replies are listed 'Best First'.
Re^5: splitting a sequence using unpack
by Anonymous Monk on Mar 01, 2005 at 13:05 UTC
    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.