[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [FWP] Closest hash value
On Mon, Jul 19, 1999 at 09:31:51AM -0700, Larry Rosler wrote:
> > FD> You can get the "first" key with
> >
> > FD> ($best) = each %h;
> >
> > I know, but I'm not sure if that is optimized. It may cause all
> > 1_000_000 keys to be copied to the stack and then the first item
> > removed.
> >
> > Anyone know for sure?
>
> You have it backwards. 'for keys %h' creates a list of all the keys.
> 'each %h' returns one key-value pair, and stores the value of an
> iterator for succeeding calls.
Also, in a scalar context each() returns just the key, so the parens are
unnecessary.
Ronald
==== Want to unsubscribe from Fun With Perl? Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
==== unsubscribe