Perl Christmas Quiz 2009

Graham Barr gbarr at pobox.com
Mon Nov 30 21:22:04 GMT 2009


On Nov 30, 2009, at 3:17 PM, Graham Barr wrote:

> 
> 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.

I meant to add that this change to sort was added to 5.6.0. So to answer your question it was nearly a decade ago :-)

Graham.




More information about the london.pm mailing list