in reply to Re: splitting a string into arbitrary lengths
in thread splitting a string into arbitrary lengths
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: splitting a string into arbitrary lengths
by moot (Chaplain) on Jun 23, 2005 at 02:20 UTC |