[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] pop (keys %hash) ?



On Fri, Jun 18, 1999 at 09:55:32AM -0700, jean-Francois Jobidon wrote:
} @listKeys = (keys %hash);
} $lastkey = pop @listKeys;
} 
} I'd like to know if there is a way to write this code
} on one line. Something like :
} 
} $lastkey = pop (keys %hash);

You can do things like (keys %hash)[-1].  But your more fundamental
problem is that there's no guarantee that the elements in a hash are
in any particular order, so the "last key" has no actual meaning.  If you
want strict order, use an array.

} 
} Perl tells me that the argument must be an array.
} Thanks
} JF Jobidon
} 
} _________________________________________________________
} Do You Yahoo!?
} Get your free @yahoo.com address at http://mail.yahoo.com
} 

-- 
Paul Schinder
schinder@pobox.com

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org