in reply to Re: What's wrong with my code? [from a beginner]
in thread What's wrong with my code? [from a beginner]

The passed argument list is ignored, but the array is within scope, and so is accessible within get_throughput.

Caution: Contents may have been coded under pressure.
  • Comment on Re^2: What's wrong with my code? [from a beginner]

Replies are listed 'Best First'.
Re^3: What's wrong with my code? [from a beginner]
by Ardemus (Beadle) on Jan 28, 2005 at 00:23 UTC
    To clarify passing values to a subroutine
    The arguments for a subroutine are treated as a list assignment to the @_ list. This script demonstrates a few key concepts:

    my @entry = ('ListItem1', 'ListItem2'); $ScalarContext = &get_throughput($Var1, $Var2, @entry, $Var3, \@entry) +; @ListContext = &get_throughput($Var1, $Var2, @entry, $Var3, \@entry); sub get_throughput { my $GetsVar1 = shift @_; #@_ is a list of your arguments my $Scalar = shift; # gets $Var2, @_ is the default for s +hift my ($List1, $List2) = @_; #@_ your list was added to @_ as indi +vidual elements my (undef, undef, $Var3) = @_; #undef discards return values my $ListRef = $_[4]; #a reference to your list #see docs for more info on refs return wantarray ? @list : $Scalar; }
    Ardemus "This, right now, is our lives."