It was Friday, October 10, 2003 when Jeff Westman took the soap box, saying:
: Question:
: 
: If I have an array and want to take the first element off and return it, I
: would do it like this:
: 
:    return (@myArray) ? shift(@myArray) : undef;
: 
: How would I do similarly with a hash?  I have something like this:
: 
: 
:    return (exists $myHash{$val1} ) ? $Hash{$val2} : undef;
: 
: But these leaves the value in the hash.  I know I can save the value first,
: then DELETE it, and then return it.  But I'd like to do it all in one step.

When you call delete(), it deletes the element from the hash *and*
reurns that element's value.  This is very handy.

return (exists $myHash{$val1}) ? delete $myHash{$val2} : undef;

  Casey West

-- 
"Stocks have reached what looks like a permanently high plateau."
 -- Irving Fisher, Professor of Economics, Yale University, 1929.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to