Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: Curios use of regular expressions in split

by juliosergio (Sexton)
on Feb 16, 2012 at 00:57 UTC ( #954113=note: print w/replies, xml ) Need Help??

in reply to Re: Curios use of regular expressions in split
in thread Curios use of regular expressions in split

Great! Finally I'm understanding what's behind the split function!

When you enclose the expression with parenthesis, the string is splitted according to the pattern but the matched separators are also stored in the resulting array. That's really interesting, because you can easily manipulate in the same array both, the separated stuff and the separators. See my example below:

#! /usr/bin/perl use Data::Dumper; $re = "(ab+)"; $input = "uno abb dos ab tres abbb cuatro"; my @splits = split /$re/, $input; print "splits: ", Dumper \@splits; __END__ splits: $VAR1 = [ 'uno ', 'abb', ' dos ', 'ab', ' tres ', 'abbb', ' cuatro' ];

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954113]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2017-02-26 19:23 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (376 votes). Check out past polls.