Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Answer: Is it possible to do pass by reference in Perl

by chromatic (Archbishop)
on Apr 04, 2000 at 01:53 UTC ( #6766=categorized answer: print w/replies, xml ) Need Help??

Q&A > subroutines > Is it possible to do pass by reference in Perl? - Answer contributed by chromatic

Prepending a variable with a backslash (\) creates a reference:
my $scalar = "this is a scalar"; my @array = qw( this is my array ); my %hash = ( 'this' => 'my', 'hash' => 'mine',); print_all(\$scalar, \@array, \%hash); sub print_all { my $scalar_ref = shift; my $arr_ref = shift; my $hash_ref = shift; print "Scalar: ", $$scalar_ref, "\n"; print "Array: ", join ' ', @$arr_ref, "\n"; print "Hash: ", each %$hash_ref, "\n"; }
See perlman:perlref for the juicy details.