develooper Front page | perl.perl5.porters | Postings from May 2008

Re: [perl #54974] Strange map {} Behavior When Returning Two Values

Thread Previous | Thread Next
Aristotle Pagaltzis
May 29, 2008 06:16
Re: [perl #54974] Strange map {} Behavior When Returning Two Values
Message ID:
* H.Merijn Brand <> [2008-05-29 13:00]:
> using a semi-colon
> $ perl -wle'my@a=map{;"--$_"=>$_}@ARGV;print"(@a)"' foo bar
> (--foo foo --bar bar)
> using parens
> $ perl -wle'my@a=map{("--$_"=>$_)}@ARGV;print"(@a)"' foo bar
> (--foo foo --bar bar)
> using a unary +
> $ perl -wle'my@a=map{+"--$_"=>$_}@ARGV;print"(@a)"' foo bar
> (--foo foo --bar bar)
> using catenation
> $ perl -wle'my@a=map{"--".$_=>$_}@ARGV;print"(@a)"' foo bar
> (--foo foo --bar bar)
> I personally think that using parens here to disambuigate is
> the most verbose option without adding unexplainable line noise

Which in my mind makes it the least desirable, since that makes
it “obviously” superfluous and therefore the most likely to be
removed by some overeager maintainer. The semicolon, OTOH, is so
unusual that it is much more obviously intentional, even if the
maintainer who discovers it doesn’t know what it’s there for. It
probably won’t prevent them from removing it, but I would expect
that after the code breaks they will conclude that the semicolon
was put there purposely to prevent that error. With parens, in
contrast, it seems more likely to me that the maintainer will
think the code worked just by accident because the previous
programmer wrote it in a peculiar style with no particular

Aristotle Pagaltzis // <>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About