Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: can split() use a regex?

by eXile (Priest)
on Jun 17, 2006 at 15:18 UTC ( #555982=note: print w/ replies, xml ) Need Help??


in reply to can split() use a regex?

If you really wanted to split on '\d+\s+' you'd need to single quote the regex, ie:

my ($one, $two) = split('\d+\s+', $line);


Comment on Re: can split() use a regex?
Download Code
Replies are listed 'Best First'.
Re^2: can split() use a regex?
by davidrw (Prior) on Jun 17, 2006 at 16:02 UTC
    or use (and IMHO better because it clearly designates it as a regex to the reader) the normal //:
    my ($one, $two) = split( /\d+\s+/, $line);
    BUT.. you need the delimeter as $one .. so need to capture it:
    my ($one, $two) = split( /(\d+\s+)/, $line);
    BUT .. that will have the space in $one .. so use a look-behind (see perlre) instead .. (and add the LIMIT)
    my ($one, $two) = split /(?<=\d+)\s+/, $line, 2;
    so to OP -- yes, it's possible w/split & regex ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (13)
As of 2015-07-08 02:46 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 (93 votes), past polls