Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] perl hashes
- Date: Thu, 18 Sep 2003 15:55:03 +0900
- From: Neil Bortnak <nbortnak@example.com>
- Subject: Re: [tlug] perl hashes
- References: <20030918153325.FE09.B-ROBSON@example.com>
- Organization: Cisco Japan KK
Hi Brett, The best (only?) way to pass a hash is by using a reference. Like this: print_hash(\%foo); sub print_hash { my $hash_ref = shift; foreach my $i (keys(%$hashref)) { print("Hash Name: $i, Hash Value: $$hash_ref{$i}\n"); } } The backslash during the function call passes the not the hash, but a reference to the hash. Using the reference is easy. Use it normally (under it's new name) but add a $ sign after the first symbol ($$hash_ref{blah} for a member item and %$hash_ref to access the hash itself). Sometimes you may need to use an alternate syntax (${$hashref}{blah}) which is documented in perlref along with everything else you might need. Sorry if I was too verbose! Neil On Thu, 2003-09-18 at 15:35, Brett Robson wrote: > Quick perl question. > > Passing a hash to a subroutine is just a matter of treating it as a > scalar isn't it? > > Brett > > eg > > %foo > > &bar ($foo) > > > sub bar { > > my ($foo)= @example.com; > > # foo is now available as a hash > > } > > > > > > -- > Brett Robson > Systems Administrator > GOL > http://www.gol.com > Phone: 03-3239-6856 International: +81-3-3239-6856
- References:
- [tlug] perl hashes
- From: Brett Robson
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] perl hashes
- Next by Date: Re: [tlug] perl hashes
- Previous by thread: Re: [tlug] perl hashes
- Next by thread: Re: [tlug] perl hashes
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links