in reply to Re^2: if block inside map
in thread if block inside map

You can also leave off the else branch, in which case map would return the empty string (not sure why not undef) when the if-condition isn't true...     (Emphasis added)

See Re: Map Function Weirdness and Re: Map Function Weirdness (and ikegami's elaboration thereto Re^2: Map Function Weirdness) to Map Function Weirdness.

Replies are listed 'Best First'.
Re^4: if block inside map
by Eliya (Vicar) on Nov 11, 2011 at 23:57 UTC

    Thanks for the pointer.  I must admit that thread somehow happened to sneak out from under my radar :)

    Personally, I would consider it more "natural" if an if-construct without an else clause (when used in an "expression context") would sematically behave more like a ternary cond ? ... : undef (instead of cond ? ... : cond), but if you look at it from the perspective of what is evaluated last, it's of course perfectly clear why things behave as they do.

    (Yes, I'm aware that if-constructs in Perl - unlike in some other languages - don't evaluate to anything itself (as a whole), i.e. they are not expressions — so no need to comment on that.)