in reply to map a list
If you really want to write it that way, I think you'd need to use do {...}, e.g. something like this
my $s = "a,b=c,e=#f"; sub fn { "fn(@_)" } # dummy function my %result = map { /=#/ ? do { my @l = split(/=#/,$_,2); ( $l[0], fn($l[1]) ) } : /=/ ? split(/=/,$_,2) : ($_,fn($_)) } split(/,/, $s); use Data::Dumper; print "$s\n"; print Dumper \%result;
Output:
a,b=c,e=#f $VAR1 = { 'e' => 'fn(f)', 'a' => 'fn(a)', 'b' => 'c' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map a list
by evil_otto (Novice) on Mar 12, 2007 at 20:48 UTC |