Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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.

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2016-10-27 16:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (366 votes). Check out past polls.