Perllace has asked for the wisdom of the Perl Monks concerning the following question:

Please have a look at this code and let me know what I'm doing wrong that the values of the hash is not getting printed in the function CatchText.

Wait(test,2000,0.96); sub Wait { my ( $tag, $duration,$thresh ) = @_; my $threshvalue = $thresh || "0.95" ; my $tmp = { 'Command' => 'Wait', 'Tag' => $tag, 'Duration' => $duration, 'Threshold'=> $threshvalue }; CatchText($tmp); } sub CatchText { my ($self,$hash) = @_; my $str = $hash->{'Threshold'}; print "The command is $str \n"; }

I am getting the output as "The command is "

Thank you

Replies are listed 'Best First'.
Re: Why is the valu of the hash not geting printed
by ikegami (Patriarch) on Nov 07, 2011 at 07:36 UTC
    You pass one argument to CatchText, and you expect the parameter second to contain something.
Re: Why is the valu of the hash not geting printed
by Anonymous Monk on Nov 07, 2011 at 07:45 UTC

    The obscure methodology of Perl's object orientation system has thrown you off here... remove the reference to $self and it should work :

     my ($hash)  = @_; L
      Ignore that capital L as well.
        Thank you ..It works just fine :)
Re: Why is the valu of the hash not geting printed
by mrstlee (Beadle) on Nov 07, 2011 at 15:11 UTC
    Note that you don't have to set up a temporary variable for the call to CatchText, or for the threshold.
    ... CatchText({Command => 'Wait', Tag => $tag, Duration => $duration, Threshold => $thresh || 0.95, });
    You don't have to quote the hash keys either, so long as they are valid perl identifiers.