On Thursday, Sep 4, 2003, at 04:53 US/Pacific, Andrew Brosnan wrote:
On 9/4/03 at 11:34 AM, [EMAIL PROTECTED] (B. Fongo) wrote:
An argument passed to a subroutine returns wrong value.

Code example:
[..]
In both cases, the script prints out 1.
What is going on here?

You are asking Perl for the number of elements in @_.


If you want the value(s) from @_, then
     my $forwarded = shift;
     or
     my ($forwarded) = @_;

there is also the minor defect that the sub



sub showValue { my ($forwarded) = @_; print $forwarded; }

will generate something like "ARRAY(0xdba8)"
which is the Reference - not the content - he
will most likely want to deal with what the reference passed, eg:
        
        my @x =  (1..5);
        
        print "#----------\n";
        
        showValue([EMAIL PROTECTED]);
        print "\n#----------\n# Calling the Pretty \n";
        pretty_show_values([EMAIL PROTECTED]);
        
        sub showValue {
          my $forwarded = shift;
          print @$forwarded;  # print ${$forwarded};
        }
        
        sub pretty_show_values {
          my $forwarded = shift;
          print "@$forwarded\n";  # print ${$forwarded};
        }

also it is simpler to just 'dereference' the array directly.

ciao
drieux

---


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



Reply via email to