in reply to Re: Re: foreach loop question
in thread foreach loop question
I should have been more explicit. It's "keys" that creates the new array, not the sort.
If you want to process all of the keys and values in a hash without creating a new array to hold the hash keys, look into "each".
This doesn't create an additional array. Note, though, that it's unsafe to manipulate the hash while you're iterating over it. The proviso in the docs reads:while ( ($key, $value) = each %h ) { ...
If you add or delete elements of a hash while you’re iterating over it, you may get entries skipped or duplicated, so don’t. Exception: It is always safe to delete the item most recently returned by "each()".
|
|---|