Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: splitting a string into arbitrary lengths

by bmann (Priest)
on Jun 22, 2005 at 22:03 UTC ( [id://469219]=note: print w/replies, xml ) Need Help??


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
    crap, you're right. good catch.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://469219]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found