On 25-Mar-2001 Oded Arbel wrote:
> I have a simple perl question, if you please :
> I have a function that needs to return a hash (%) to the caller - it
> <snip>
> if (!defined %result) {
You can cheat with typeglobs. Test this:
$give_answer = 1; # check it with 0
sub foo {
local %bar = (1 => 'a', 2 => 'b');
return ($give_answer) ? \%bar : undef;
}
*kuku = foo; # here is the magic...
print (defined %kuku ? "Yes\n" : "No\n");
The real question you should ask yourself is:
Why assigning undef to %array didn't work?
Hints:
1. When you thought you returned %array, you were
wrong. The function returned a list of (key, value) pairs
2. What's is the context in which the function is called?
3. What happens if you assign? (and why?)
%x = 5;
(Check the keys and the values)
Now you should have the answer...
Cheers,
------------------------------------------------
Oron Peled Voice/Fax: +972-4-8228492
[EMAIL PROTECTED] http://www.actcom.co.il/~oron
3Com only purchased rights to the numbers '3' '5' and '9', Intel
owns '4', '8', '6', and '2'. '0' and '1' are still in the public
domain ;-)
-Donald Becker
=================================================================
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]