in reply to Is an empty block not a block?
Generally speaking, an empty set is going to be treated as a hashref. If, for some unfathomable reason, you want a no-op block, stick a semicolon inside it:
Perl sees that you've got code (an empty statement) in there, so it must be a code block. No warning about Useless use of single ref constructor like you'd get if you used {}; instead. (I turned on warnings so you could see a difference.)perl -we "use strict; {;} no strict 'refs';"
Conversely, if you want to make Perl interpret what looks like a block of code to be a hashref, put it in parentheses or stick a plus on the front. (I personally dislike the + convention.)
The second example is half as useless. :-)F:\Perl>perl -we "use strict; {qw(key val)}; no strict 'refs';" Useless use of a constant in void context at -e line 1. Useless use of a constant in void context at -e line 1. F:\Perl>perl -we "use strict; ({qw(key val)}); no strict 'refs';" Useless use of single ref constructor in void context at -e line 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is an empty block not a block?
by diotalevi (Canon) on Nov 18, 2005 at 22:29 UTC |