Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Send hash of hash arguments to sub

by Laurent_R (Vicar)
on Aug 14, 2013 at 08:26 UTC ( #1049399=note: print w/ replies, xml ) Need Help??


in reply to Send hash of hash arguments to sub

As it has already been said, it seems pointless to use a subroutine in such a case. However, assuming you want to fix your code and understand what's going on, you would need to pass a hash ref, rather than the hash itself, as explained by others above, including kcott. Or another fix would be to put your hash as the last element of your argument list:

sub probability { my ($source, $target, %hash) = @_; return $hash{$source}{$target}; } my $proba = probability($key_level1, $key_level2, %hash);

This way, the hash does not "eat" the trailing arguments.

Update: Corrected a copy_and_paste error and the missing name of the subroutine in the function call. I had to go, I was too hasty on typing this.


Comment on Re: Send hash of hash arguments to sub
Download Code
Re^2: Send hash of hash arguments to sub
by Anonymous Monk on Aug 14, 2013 at 09:55 UTC

    You are not passing a hash ref. and neither do you have the variable $hash_ref defined. Then the subroutine is not called anywhere.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-30 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls