Read perldata, perlsyn, perlref and perlsub (if perlsub exists).
There are no pointers in perl, there are only scalar's hashes's and array's, and references. Some might say there are also lists, and they're right.
subroutines get arguments via the magical @_ variable, meaning every time you say Foo(1,2,3), inside of sub Foo, the @_ array will contain 1,2 and 3 as it's value.
That's pass-by-value.
Here are some more examples.my @Arra = ( 1, 2, 3, 4 ); PassByReference(\@Arra); sub PassByReference { die "@_"; }
use Data::Dumper; DIE(1..10); DIE(1,2,3,4,5,6,,8,9); DIE( [ 1..10 ] ); DIE( { 1..10 } ); my @ARRAY = 1..10; my %HASH = @ARRAY; DIE( @ARRAY ); DIE( %HASH ); DIE( \@ARRAY ); DIE( \%HASH ); DIE( @ARRAY, \%HASH ); DIE( \@ARRAY, \%HASH ); DIE( \@ARRAY, %HASH ); DIE( \&DIE ); ¨ DIE(); sub DIE { print Dumper(@_) };
In reply to Re: Subroutine args by-value vs. by-ref
by Anonymous Monk
in thread Subroutine args by-value vs. by-ref
by dpenny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |