in reply to How to have a subroutine return an undefined hash

Putting aside the question of what an "undefined hash" might be, what you might do is return undef on failure and a reference to a hash if all goes well. Aside from being easier to deal with, this will be more efficient since the hash contents won't get flattened into a LIST and copied back into the destination hash.

sub getHash { ... if( $hunky_dory ) { return \%ret_value; } else { return undef } } my $hash_ref = getHash( ); unless( defined $hash_ref ) { die "Woe is me\n"; } # ... get on with it ...

Replies are listed 'Best First'.
Re^2: How to have a subroutine return an undefined hash
by loris (Hermit) on Apr 27, 2005 at 07:47 UTC

    Thanks for the help, Fletch and everyone else.

    The idea of returning a reference to the hash was the bit of wisdom I was lacking.

    loris