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

Re: Curios use of regular expressions in split

by Riales (Hermit)
on Feb 15, 2012 at 17:39 UTC ( #954012=note: print w/ replies, xml ) Need Help??


in reply to Curios use of regular expressions in split

I don't know if anybody has a better solution, but you could just take two steps to both capture what you want to capture and split the string:

my $string = "uno abc dos"; my @a = split /abc/, $string; $string =~ /(abc)/; ...some use of $1...

If your pattern is just something as trivial as abc, you could just assume $1 = 'abc'...but I'm assuming it's not.


Comment on Re: Curios use of regular expressions in split
Select or Download Code
Re^2: Curios use of regular expressions in split
by Anonymous Monk on Feb 15, 2012 at 17:45 UTC
    my @matches = $input =~ /$re/g; my @splits = split /$re/, $input;
Re^2: Curios use of regular expressions in split
by juliosergio (Acolyte) on Feb 15, 2012 at 18:55 UTC

    Up to now, I think yours is the best solution, though, I was trying to do it in a single step..
    Thanks!,
    -Sergio

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-11-27 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (188 votes), past polls