Perl Christmas Quiz 2009

Paul Johnson paul at pjcj.net
Mon Nov 30 20:57:53 GMT 2009


On Mon, Nov 30, 2009 at 12:14:21PM -0800, 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.

But you couldn't use too old a perl or it would get upset by the "for
my".  So probably 5.4.x or so would be the ticket.

-- 
Paul Johnson - paul at pjcj.net
http://www.pjcj.net


More information about the london.pm mailing list