On Thu, Dec 22, 2005 at 02:53:39PM +0100, TSa wrote: > HaloO, > > Luke Palmer wrote: > >Recently, I believe we decided that {} should, as a special case, be > >an empty hash rather than a do-nothing code, because that's more > >common. > > Ups, is that distinction needed eagerly? Wouldn't the return value > of a do-nothing code return a value that when coerced into hashness > result in an empty hash? Avoiding this superflous call is more of > interest to the optimizer than code correctness. OTOH, implementing > an empty block is easy as well.
Well, I assume that the do-nothing sub is assigned into the variable, and gets re-evaluated each time the variable is use. Which would mean that you'd get a new (different) empty hash each time. Whereas an empty hash constructor gives you a hash reference to keep. (not just for Christmas) It's like the autovivification bug: sub stuff { my $h = shift; $h->{k}++; } my $a; $a->{$_}++ for @ARGV; stuff($a); print "$a->{k}\n"; __END__ Nicholas Clark