Presumably, since every "array" in PHP is really just an associative array (whether or not the indexes are numeric), situations like the one above never cause a problem.# somewhere, some step ends up doing something like: $index = 256 * 2048 * 1024 * 1024 * $i; # for some value of $i >= 1 # and then, shortly afterwards, something like this happens: $array( $index ) = "foobar";
That sort of thing would not cause a problem in Perl either, if you are using a hash. But Perl gives you the opportunity of using an array instead ($array[$index]='foobar' rather than $hash{$index}='foobar'), and when you give a ridiculously large index value for an element in an array, Perl is obliged to make sure that memory is allocated to hold all the array slots between "0" and the given index value.
So, if you are being careless in your use of (numerically indexed) arrays in perl -- when you should really be using a hash instead -- what is actually happening, in effect, is that perl is giving you enough rope to hang yourself, whereas PHP is allowing you to ignore the fact that your numeric "array" index values may sometimes be insane (and obviously bug-ridden).
Not a perfect world, either way...
In reply to Re: Difference between array and a hash? (Newbie concerns)
by graff
in thread Difference between array and a hash? (Newbie concerns)
by reztlaf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |