Related Items  

Linux and Windows IT Support  

We make IT Support easy!

Windows, Apple and Linux IT support and services.

Login or Register  

If you wish to contribute an article, please login or register.

Passing a hash reference to a subroutine (Perl)

PrintE-mail

perl_logoQ. How do I pass a hash reference to a subroutine in Perl?

A. This can be achieved by preceeding the hash with a slash when passing:

#assume you have a hash
my %results = (start_date => "may 1", end_date => "sep 1");

#pass the hash
test(\%results);

#your subroutine
sub test {
my $ref = shift;

# assign new variable
$ref->{'start_date'} = "new date";

}

Comments (1)
:-)
1 Wednesday, 06 January 2016 14:55
David
This is exactly what I needed to see. Thank you!

Add your comment

Your name:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.24.0
   
Copyright © 1999 - 2017 Virtual Helpme | Trusted IT Services | Original Template: Allrounder
-->