B. Fongo wrote:

Hello


Please don't cross post



An argument passed to a subroutine returns wrong value.


Code example:

@x = (1..5);
$x = @x;


You are trying to assign an array to a scalar. An array evaluated in a scalar context gives the no elements present in it. In this case the value 5 will be assigned to $x.



showValue ($x); # or showValue (\$x);



sub showValue {
my $forwarded = @_;



Assigning an array to a scalar again. In this case the array @_ is an one element array containing the value 5 or the reference to $x depending on your call (perldoc perlsub).



print $forwarded; # print ${$forwarded};



If the strict pragma had been enabled (use strict), print ${$forwarded} will result in a fatal error.



}


In both cases, the script prints out 1.
What is going on here?

Thanks

Babs





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to