Perl Christmas Quiz 2009
Dermot
paikkos at googlemail.com
Tue Dec 1 16:52:15 GMT 2009
2009/12/1 Matt Sergeant <msergeant at messagelabs.com>:
> On Tue, 1 Dec 2009 11:23:09 -0500, Matt Sergeant wrote:
>> On Mon, 30 Nov 2009 18:24:12 +0000, Chris Jack wrote:
>>> 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";
>>
>> Bizarrely enough, on both my Snow Leopard machines (default perl
>> install) this outputs: 4D
This is one of those situation where I should keep quiet to avoid
showing my ignorance but I can't help myself.
My first impression was that it would be 4. However, without running
it, I would say 0 on the basis that $b is scoped within the loop and
(not sure about this point) is a copy of the value in $a{1}.
I await the flak.
Dp.
More information about the london.pm
mailing list