On Sun, 25 Mar 2001, Oded Arbel wrote:
> Hi list!
>
> I have a simple perl question, if you please :
> I have a function that needs to return a hash (%) to the caller - it does so
> something like this :
> <snip>
> return %temp;
> </snip>
> and I call it like this :
> <snip>
> %result = subname(params);
> </snip>
> now, I want to detect when that functin fails completly, so - when it does
> this, it returns a non-defined value :
> <snip>
> return undef.
> </snip>
> and now when I try to detect it :
> <snip>
> if (!defined %result) {
> </snip>
> it ofcourse doesn't work. so my question is - how should I try to detect the
> undefined value ?
>
I advise you to pass the Hash as a reference. Like this:
sub myfunc
{
...
return \%temp;
}
And then
$hash_ref = myfunc();
Then you can check if $hash_ref is undef. If it's not: you can dereference
it into a hash:
%hash = %{$hash_ref};
For more information consult the perlref manpage.
Hope it helps.
Shlomi Fish
----------------------------------------------------------------------
Shlomi Fish [EMAIL PROTECTED]
Home Page: http://t2.technion.ac.il/~shlomif/
Home E-mail: [EMAIL PROTECTED]
The prefix "God Said" has the extraordinary logical property of
converting any statement that follows it into a true one.
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]