Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

( #6766=categorized answer: print w/ replies, xml ) Need Help??

Q&A > subroutines > Is it possible to do pass by reference in Perl? 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.

Comment on Answer: Is it possible to do pass by reference in Perl
Download Code
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (20)
As of 2015-07-07 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls