Re: How can pass hash to subroutine ?
[email protected] ("Jeff Peng")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Jun 13, 2008 at 7:50 PM, sivasakthi <[email protected]> wrote: > Hi all, > > how can we pass hash to subroutine? and retrieving the hash in > subroutine to print values of hash. > Hello, Generally we use a reference. my %hash = (1,2,3,4); mysub(\%hash); sub mysub { my $hashref = shift; print $hashref->{1}; } or you could pass hash directly to a subroutine, mysub(%hash); sub mysub{ my %hash = @_; print $hash{1}; } -- Jeff Peng - [email protected] Professional Squid supports in China http://www.ChinaSquid.com/