Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: splitting a string into arbitrary lengths

by kirbyk (Friar)
on Jun 22, 2005 at 21:34 UTC ( #469204=note: print w/ replies, xml ) Need Help??


in reply to splitting a string into arbitrary lengths

You could do it with a regex as well:

my ($tyear, $tmon, $tday) = ($today =~ /(\d{4})(\d{2})(\d{2})/);
This would be a good route if you had a less standard format, like optional dashes.

-- Kirby, WhitePages.com


Comment on Re: splitting a string into arbitrary lengths
Download Code
Replies are listed 'Best First'.
Re^2: splitting a string into arbitrary lengths
by ihb (Deacon) on Jun 23, 2005 at 20:49 UTC

    That is what I'd perhaps use too, depending on the application. If I'd chose this way I'd even tag along a success check (and add anchors). Your format may change some day and then you'll be glad you caught that.

    my ($y, $m, $d) = $today =~ /^(\d\d\d\d)(\d\d)(\d\d)\z/ or die "Incorrect date format: '$today'";

    ihb

    See perltoc if you don't know which perldoc to read!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-31 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls