[tpm] Schrodinger's hash ?

Shlomi Fish shlomif at shlomifish.org
Sat Jun 23 02:47:53 PDT 2012

Hi Indy,

On Fri, 22 Jun 2012 14:30:43 -0400
"Indy Singh" <indy at indigostar.com> wrote:

> I would just change the while loop to:
> foreach (keys %hash) {
>     $index = $_;
>    $object = $hash{$index}
> }

This code is non-idiomatic. I would write it as:

foreach my $key (keys %hash)
	my $object = $hash{$key};
	# Do something with $key and $object



> It doesn’t explain why your hash appears empty, but if the print work, then this code should work just as well.
> A while on an array or hash is odd coding, unless you intend to change the array inside the loop – but that is an odd thing to do too.

Actually while (my ($k, $v) = each %hash) is idiomatic - just somewhat flaky.


	Shlomi Fish

> Indy Singh
> IndigoSTAR Software -- www.indigostar.com

Shlomi Fish       http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity

The KGB used to torture their victims by having them look at scrolling XSLT

Please reply to list if it's a mailing list post - http://shlom.in/reply .

More information about the toronto-pm mailing list