How can I map a list (a,b) into (a,fn(b)) in the context of a ternary operator?

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:

@result=map { /=/ ? split(/=/,$_,2) : ($_,fn($_)) } split(/,/, $string);
Adding in the x=>fn(y) case is where I'm having trouble; my first attempt:
@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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.