Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 rifling through the Monastery: (5)
As of 2014-12-22 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls