[Israel.pm] Perl Advocacy

Gabor Szabo gabor at pti.co.il
Wed Dec 29 11:09:03 PST 2004


>> while ( ($key, $val) = each(%myhash) ) {...}   # $key is a string
>> while ( ($key, $val) = each(@myarray) ) {...}   # $key is an integer
>
> You want $key in the second line to be the index? 1, 2, 3 etc.?
>
> Then write the almost equivalent
>
>     for my $key (0 .. $#myarray) {
>         my $val = $myarray[$key];
>         ...
>     }

I am not that coninced that having a unified view of hashes and array
(which are then basically hashes with only numbers as keys)
is a bad thing. It does hide some complexity (and produces a speed penalty 
I guess).

Nothing would happen if

     keys %myhash;

would always return the keys sorted numerically.


They still cannot have arrays as keys to arrays so Python must be
superior to PHP as well.

http://il.php.net/manual/en/function.array.php

Gabor



More information about the Perl mailing list