[Israel.pm] Perl Advocacy
offer.kaye at gmail.com
Wed Dec 29 23:34:44 PST 2004
On Thu, 30 Dec 2004 09:10:44 +0200, david istermann wrote:
> Offer Kaye wrote:
> > If your problem requires iterating over each and every element of the
> > data, then using a hash, IMHO, is just *plain wrong*.
> Then why there is a function called "each" for iterating over a *HASH* ?!
Because sometime you *really, really, really* do need to iterate over
your data, even though, most of the time, you need direct access by
key. So you store the data in a hash, but use the "each" function when
you *have to*. But don't take that as a license to use a hash as you
would an array - why pay for the performance overhead? Not to mention
dealing with stuff like hashes returning data in random order, when
usually if you're using a hash you want to save _ordered_ data.
> Cool! We don't need the each() function! Then why the hell is it
> present in the language?! 1 off. Why is there 'foreach' if it's just
> an alias to 'for'? Another 1 off. We could shrink Perl's core
> namespace by half this way...
And once you finish shrinking it so that you end up with "There Is
Only One Way To Do It", you find out you're re-invented Python ;-)
More information about the Perl