Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Send hash of hash arguments to sub

by Laurent_R (Canon)
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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049399]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2018-06-20 07:59 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.