Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: split help

by thinker (Parson)
on Sep 22, 2003 at 17:36 UTC ( #293206=note: print w/ replies, xml ) Need Help??


in reply to split help

Hi AM,

This should do what you want. See perldoc -f split

#!/usr/bin/perl use strict; use warnings FATAL => 'all'; my $str = "DATETIME 09:59:11"; my $time = (split " ", $str)[1]; my ($h,$m,$s) = split ':', $time; print $h;

Hope this helps

thinker

Update Answered the question that was asked, not the one I imagined :-)


Comment on Re: split help
Download Code
Re: Re: split help
by matthewb (Deacon) on Sep 23, 2003 at 15:32 UTC
    Somewhat daft but I notice that no one has mentioned the third argument to split yet:

    use strict; use warnings FATAL => 'all'; # ;) my( $one, $two ) = split /:/, q[DATETIME 09:59:11], 2; print substr( $one, -2 );

    From perldoc -f split:
    If LIMIT is specified and positive, it represents the maximum number of fields the EXPR will be split into, though the actual number of fields returned depends on the number of times PATTERN matches within EXPR.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-09-20 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls