Perl Christmas Quiz 2009

Randal L. Schwartz merlyn at stonehenge.com
Tue Dec 1 17:06:01 GMT 2009


>>>>> "Dermot" == Dermot  <paikkos at googlemail.com> writes:

Dermot> My first impression was that it would be 4. However, without running
Dermot> it, I would say 0 on the basis that $b is scoped within the loop and
Dermot> (not sure about this point) is a copy of the value in $a{1}.

That's the nice thing about foreach.  The loop variable is aliasing,
not copying, so if there are lvalues in the list, they retain their
lvalue-ness:

 $_ *= 3 for @somelist;

multiplies each element by 3, for example.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the london.pm mailing list