develooper Front page | perl.perl5.porters | Postings from October 2009

Re: "If" your subscript goes bump in the night

Thread Previous | Thread Next
From:
demerphq
Date:
October 31, 2009 04:24
Subject:
Re: "If" your subscript goes bump in the night
Message ID:
9b18b3110910310424j1ef353dexf2f4c534e67ecaa2@mail.gmail.com
2009/10/31 Aristotle Pagaltzis <pagaltzis@gmx.de>:
> * George Greer <perl@greerga.m-l.org> [2009-10-31 00:40]:
>> I suppose the answer could be "if you're subscripting a hash at the
>> end of an 'if' then you must include the parentheses" but that's a
>> little too circumstantial for my tastes and potentially surprising if
>> someone writes:
>>
>>       sub return_baz_if_foobar { if $foo{bar} { "baz" } }
>>
>> and suddenly gets a "can't use string as a HASH ref" error.
>
> There are cases with very similar ambiguities that do not get
> resolved very intuitively:
>
>    my @hashes = map { $_ => "blah_$_" }, qw( foo bar );
>
> And there is another case where I always write `map {; ... }`
> (note the semicolon) to force block interpretation, but I’m
> racking my brain and can’t come up with what it was.
>

Pramatta like `use warnings`:

   map { no warnings; .... } @list

produces a syntax error.

   map {; no warnings; .... } @list

does not.

This is an Abigail "fingerprint" by the way. If i found that map{}
usage combined with space between subscripts on sub calls or composite
structures I would bet money Abigail wrote the code. (And I would
probably win) :-)

cheers,
Yves



-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About