in reply to Splitting up a string by lengths

You want unpack.

my $date = '20050725'; my ($y, $m, $d) = unpack('a4a2a2', $date); print "$y / $m / $d\n";
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Splitting up a string by lengths
by kwaping (Priest) on Jul 25, 2005 at 14:46 UTC
    ^^^ Nice!! I never would've thought of that. I'll be using that a lot in the future.

    Update: This is turning into a nice TIMTOWTDI thread!
      in reasonably recent perls, you can do stuff like this:
      my @cc = unpack("(A4)4", "1234567890123456");
      instead of the more verbose
      my @cc = unpack("A4A4A4A4", "1234567890123456");
      I've used it in the past with great success. Besides...it might improve your golf game. :)

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        Good additional info, thanks!