[tpm] Schrodinger's hash ?

Fulko Hew fulko.hew at gmail.com
Fri Jun 22 11:32:14 PDT 2012


On Fri, Jun 22, 2012 at 2:07 PM, Mike Stok <mike at stok.ca> wrote:

> Have you been iterating over the hash before the keys in the print resets
> the iterator?  Maybe the iterator was all but done.
>

Enhancing Mikes sample code a little... this is probably whats really
happening.

I stand corrected/educated!
In hind sight, it sorta makes sense that the 'each' just gets the 'next'
thing, and it doesn't know (recognize) that it is inside a loop where
the programmer wanted to 'loop over everything'.

Unfortunately, this is probably something that will bite my behind
again in a few years (after I've forgotten this event).

<soapbox on>
Why don't languages/people make things 'intuitively safe'?
(or if they can't, then don't add features that come pre-loaded with
bullets.)
<soapbox off>

 #!/usr/bin/env perl

use strict;
use warnings;

my %h = (a => 'b', c => 'd');

while (my ($k, $v) = each %h) {
  print "$k => $v\n";
}

while (my ($k, $v) = each %h) {
  print "$k => $v\n";
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20120622/6b44013f/attachment-0001.html>


More information about the toronto-pm mailing list