Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: List::MoreUtils before, after and ... between? (1 regex)

by LanX (Chancellor)
on Feb 22, 2012 at 15:58 UTC ( #955555=note: print w/ replies, xml ) Need Help??


in reply to Re^3: List::MoreUtils before, after and ... between? (1 regex)
in thread List::MoreUtils before, after and ... between?

as a proof on concept
use Data::Dumper qw/Dumper/; sub flat (&@) { my ($code, @list) = @_; local ( $;, $_ ) = join_reliably (@list); $code->(); return split $;, $_ } sub join_reliably { # just a stub # TODO search for reliable delimiter my $delim="\0"; return $delim, join ($delim, @_); } #------------------------------ # examples #------------------------------ @list= ("a".."c","DBIC","A".."C","DANCER","a".."c"); @newlist = flat { s/.*$;DBIC$;(.*)$;DANCER$;.*/$1/ } @list; print Dumper \@newlist; # DIMTOWTDI @newlist = flat { m/DBIC$;(.*)$;DANCER/; $_=$1 } @list; print Dumper \@newlist;
OUTPUT:
$VAR1 = [ 'A', 'B', 'C' ]; $VAR1 = [ 'A', 'B', 'C' ];
UPDATE: maybe splitjoin() or sploin() are better names than just flat().

Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2016-06-25 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (325 votes). Check out past polls.