in reply to splitting a string into arbitrary lengths

How's about:
my ($y, $m, $d) = $today =~ /(\d){4}(\d){2}(\d){2}/;
..although as a previous poster mentioned, you might lose a little in readability.

Now hiring in Atlanta. /msg moot for details.

Replies are listed 'Best First'.
Re^2: splitting a string into arbitrary lengths
by bmann (Priest) on Jun 22, 2005 at 22:03 UTC
    my ($y, $m, $d) = $today =~ /(\d){4}(\d){2}(\d){2}/;

    ..although as a previous poster mentioned, you might lose a little in readability.

    You will want to move the closing parens to after the quantifiers for each group of digits, or you'll lose more than just readability ;)

    As written, the regex will only capture the last digit in each group.

    my $today = 20050622; my ($y, $m, $d) = $today =~ /(\d){4}(\d){2}(\d){2}/; print join ":", $y, $m, $d; # prints 5:6:2, not 2005:06:22
      crap, you're right. good catch.

      --
      Now hiring in Atlanta. /msg moot for details.