in reply to Re: map a list
in thread map a list

Ah! While this answer is not ideal (it doesn't preserve the case : action style of the original, which makes it more straightforward to add in another syntax when that becomes necessary), it did provide the insight for achieving wisdom: since I'm already matching the expression with a RE, I can simply use the work already done and avoid re-splitting. So:
my @result=map { /(\w+)=#(.+)/ ? ($1,fn($2)) : /(\w+)=(.+)/ ? ($1, $2) : ($_, fn($_)) } split(/,/, $str);
Thanks.

Still curious about that segfault tho...

Replies are listed 'Best First'.
Re^3: map a list
by GrandFather (Saint) on Mar 12, 2007 at 19:38 UTC

    Depending on what the larger problem is, you may be better looking at something like Parse::RecDescent. Even if you stick to manual parsing, using a more explicit coding structure as shown in dragonchild's example would pay off in terms of maintenance.


    DWIM is Perl's answer to Gödel