In the first code snippit, your function will receive a hash reference,
which is a scalar. If you get rid of the curly braces, it will work. Better
still would be....

my ($myopt, $myparams) =@_;

...and...

each %$myparams

--
Shaun Fryer
1-647-723-2729
On Jun 27, 2011 2:33 PM, <bu...@alejandro.ceballos.info> wrote:
> I am trying to send an scalar and hash to a function, but is not
> receiving the value of the hash
>
> My code is:
>
> dosomething('option',{'extraparam1'=>'hello'});
>
> function dosomething
> {
> ($myopt,%myparams) = @_;
> print "opt = $myopt\n";
> while( my ($k, $v) = each %myparams )
> { print "$k = $v \n"; }
> }
>
> And result is:
>
> opt = option
> HASH(0xcb4f490) =
> HASH(0xcb4f490) =
>
>
> I have tryied different solutions (look below) but no one
> loads/display the values of %myparams:
>
> 1) function dosomething
> {
> ($myopt,%myparams) = @_;
> print "opt = $myopt\n";
> while( my ($k, $v) = each %{$myparams} )
> { print "$k = $v \n"; }
> }
>
> 2) function dosomething
> {
> $myopt = shift;
> %myparams = shift;
> print "opt = $myopt\n";
> while( my ($k, $v) = each %$myparams )
> { print "$k = $v \n"; }
> }
>
> 3) function dosomething
> {
> use Tie::RefHash;
> ($myopt,%myparams) = @_;
> tie %hash_postparams, "Tie::RefHash";
> print "opt = $myopt\n";
> while( my ($k, $v) = each %myparams )
> { print "$k = $v \n"; }
> }
>
> Any idea what I am doing wrong?
>
>
>
> Really thank you in advance,
>
> Alejandro
>
>
> --
> To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
> For additional commands, e-mail: beginners-cgi-h...@perl.org
> http://learn.perl.org/
>
>

Reply via email to