in reply to Re: Re: Re: Re: Re: expanding the functionality of split
in thread expanding the functionality of split
sub wierd_split (\@@) { my $regex = shift; local $_ = @_ ? shift : $_; my @res; ($res [@res], $_) = split shift @$regex, $_, 2 while @$regex && le +ngth; push @res => $_ if length; @res } print "Got $_\n" for wierd_split @{[':', '::', '\s+']} => 'foo:bar::ba +z frog'; __END__ Got foo Got bar Got baz Got frog
Adding all the funny stuff of split, like using it in void context, its third parameter, or captures in the regex is left as an exercise for the reader.
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: expanding the functionality of split
by tachyon (Chancellor) on Dec 10, 2002 at 20:24 UTC |