"B. Fongo" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello

Hi

>
> An argument passed to a subroutine returns wrong value.
>
> Code example:
>
> @x = (1..5);
> $x = @x;
>
> showValue ($x);   # or showValue (\$x);
>
>
> sub showValue {
>
>   my $forwarded = @_;
>   print $forwarded;  # print ${$forwarded};
>
> }
>
> In both cases, the script prints out 1.
> What is going on here?

While assigning to $forwarded, you're allowing perl to convert from a list
to a scalar for you, this is not what you want here. You should change this
one line to the following...

my ($forwarded) = @_;

This changes $forwarded to a list context. You'll see this most often
because it's easy to maintain...

my ($forwarded, $another_paramter) = @_;

... this works just as well for any number or paramters you might pass.

What you were doing was getting the value from an array on scalar context.
When you do this in perl, it will return the __number of elements__ in the
array, which is very usefull, but not what you wanted. For example.

my $number_of_element = @a_big_array;

HTH

Rob Anderson

>
> Thanks
>
> Babs
>



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

Reply via email to