Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by LanX (Canon)
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


Comment on Re^4: List::MoreUtils before, after and ... between? (1 regex)
Select or Download Code

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 taking refuge in the Monastery: (9)
As of 2015-07-30 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls