Perl Christmas Quiz 2009

Abigail abigail at abigail.be
Mon Nov 30 21:51:46 GMT 2009


On Mon, Nov 30, 2009 at 03:22:04PM -0600, Graham Barr wrote:
> 
> 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 :-)


Which was the same release where values() returned aliases instead of copies.


Abigail


More information about the london.pm mailing list