Here's my full problem: I have a string like "a,b=c,e=#f" - comma separated terms, where each is of the form "x", "x=y", or "x=#y". I need to parse this string into a list (really, a hash), where "x" becomes x=>fn(x), "x=y" becomes x=>y, and x=#y becomes x=>fn(y). The silly part is that I'd like to do it as a ternary operator, so I can assign it without needing to put an empty declaration of the variable outside an if block.
The first two parts, x=>fn(x) and x=>y are easy:
Adding in the x=>fn(y) case is where I'm having trouble; my first attempt:@result=map { /=/ ? split(/=/,$_,2) : ($_,fn($_)) } split(/,/, $string);
@result=map { /=#/? (@l=split(/=#/,$_,2) && ($l[0],fn($l[1])) : /=/ ? split(/=/,$_,2) : ($_,fn($_)) } split(/,/, $string);
didn't quite work, and in the course of trying to debug the first branch of the ternary I got segfaults from perl:
$ perl -e ' (@n=(1,2) && ($n[1],$n[0])); (@n=(1,2) && ($n[1],$n[0])); (@n=(1,2) && ($n[1],$n[0])); ' Segmentation fault
Is this just perl trying to tell me that this is a stupid way to go about this?
In reply to map a list by evil_otto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |