develooper Front page | perl.perl5.porters | Postings from July 2001

Re: [ID 20010702.002] perldata documents dubious hash slice

From:
Mike Guy
Date:
July 2, 2001 09:02
Subject:
Re: [ID 20010702.002] perldata documents dubious hash slice
Message ID:
E15H69B-0000RA-00@draco.cus.cam.ac.uk
Nicholas Clark <nclark@copernicusgbs.com> wrote
> Surely this isn't a good example, as (I think - what am I missing?)
>
>     foreach (values %hash) {
>	...
>     }

What you are missing is that you hadn't tried it on an older Perl:

perl5.005 -lw
%h = (a => 1, b => 2);
foreach (values %h) { $_++ };
print %h;
__END__
a1b2

perl5.6.0 -lw
%h = (a => 1, b => 2);
foreach (values %h) { $_++ };
print %h;
__END__
a2b3


So it used to be an essential trick, now obsolete.

Perhaps the example should be commented "This was necessary in Perl
versions < 5.6" ?


Mike Guy



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About