Perl Christmas Quiz 2009

Graham Barr gbarr at pobox.com
Mon Nov 30 21:17:42 GMT 2009


On Nov 30, 2009, at 2:14 PM, Randal L. Schwartz wrote:

>>>>>> "Dave" == Dave Cross <dave at dave.org.uk> writes:
> 
>>> 1) Without running it to check, what does the following program output?
>>> 
>>> 
>>> my %a = (3,2,1,0);
>>> 
>>> 
>>> for my $b (sort values %a) {
>>> $b += 4;
>>> }
>>> 
>>> 
>>> print $a{1} . "\n";
> 
> Dave> Without running it, I'd say 4. Having now run it, I'm glad that's what I said
> Dave> :)
> 
> When did "sort" start returning lvalues?  I bet if you did this
> on an older Perl, it'd return 0.

sort just shuffles whatever SV* are on the stack, and values returns aliases, so
in this case you end up with aliases being returned by sort.

Graham.




More information about the london.pm mailing list