in reply to Re: Speeding up stalled script
in thread Speeding up stalled script
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.
...
Each hash or array has its own internal iterator, accessed by each, keys, and values.
— quoted from each, but see also keys and values.
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,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Speeding up stalled script
by choroba (Cardinal) on Feb 05, 2015 at 12:30 UTC | |
by Athanasius (Archbishop) on Feb 05, 2015 at 13:53 UTC | |
by BrowserUk (Patriarch) on Feb 05, 2015 at 14:30 UTC | |
by Athanasius (Archbishop) on Feb 05, 2015 at 14:38 UTC |