good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^2: Speeding up stalled scriptby Athanasius (Archbishop) |
on Feb 05, 2015 at 08:02 UTC ( [id://1115615]=note: print w/replies, xml ) | Need Help?? |
Hello sundialsvc4, Update: My conclusion was wrong, keys does consume more memory than each. See choroba’s comment and my reply, below. Is Perl going to build an in-memory anonymous array of all those keys, in order to subsequently foreach through it? No, Perl uses the same internal iterator in both cases: So long as a given hash is unmodified you may rely on keys, values and each to repeatedly return the same order as each other. Note that this internal iterator (one per hash) is implicitly reset when successive calls to each (or keys, or values) have exhausted the available hash entries. But it can also be reset explicitly, for which the recommended method is to call keys @array in void context (see values). Hope that helps,
In Section
Seekers of Perl Wisdom
|
|