| [reply] |
Under normal usage, they take values not variables. If you run the code
sub add_one {
my $x = shift;
$x += 1;
return $x;
}
You would not expect the variable you passed in (my $y = add_one($outer_x);) to change value, right? This is a little awkward/contrived, but this is in contrast to more object-oriented frameworks.
Advanced: Of course Perl actually does pass by reference with lvalues bound to @_. But that's probably the best reason for transferring subroutine inputs to locally-scoped variables.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [d/l] [select] |
$scalar = ( 1, 2, 3 );
$scalar is a variable, it exists past this line, but ( 1, 2, 3 ); is a list of value, it does not exist past that line
@array = ( 'list item 1', 2, 'another value', 'yet another value ');
an @array is a variable, it has a name, it exists past the line, it is a bucket, you store scalars inside | [reply] [d/l] [select] |