----- Original Message ----- From: "B. Fongo" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, September 04, 2003 11:34 AM Subject: passing an argument to a subroutine
> Hello > > An argument passed to a subroutine returns wrong value. What value do you want it to print? > > Code example: > > @x = (1..5); > $x = @x; Are you trying to get $x to contain "12345"? Let's assume you want to pass the @x array into your subroutine and have it print out it's contents from there. Then I think this is what you want. #!perl -w @x = (1..5); showValue (@x); sub showValue { my @forwarded = @_; foreach(@forwarded){ print "$_\n"; } } What it really comes to is what value you want to pass to your subroutine. >From reading your code, I can see that you are converting an array into a scalar but is that really what you want? Some more explanation of what you would like to acomplish would be nice. > > 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? > > Thanks > > Babs > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]