Jeff Westman wrote: > > 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.
Hi Jeff. The 'shift' built-in returns 'undef' if its operand is an empty array. Likewise, 'delete' returns either the element deleted or 'undef' if it didn't exist. It's also usual to omit 'return' on the last line of a subroutine, so you could just write: shift @myArray; and delete $myHash{$val1} to do what you want. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]