I believe this is called the typeglob approach. The original example code is below.#!/usr/bin/perl $fruit{'Apple'} = "Red"; $fruit{'Orange'} = "Orange"; $fruit{'Grape'} = "Purple"; $fruit{'Lemon'} = "Yellow"; $fruit{'Lime'} = "Green"; $myHashref=\%fruit; print "Hash reference to send = $myHashref\n"; print "Print local hash\n\n"; foreach $key (sort keys %fruit) { print $key, '=', $fruit{$key}, "\n"; } print "\nLeaving Main\n\n"; &mysubrtn($myHashref); sub mysubrtn() { local *myref = shift ; print "In my Subrtn\n"; print "Print hash via reference\n\n"; foreach $key (sort keys %myref ) { print $key, '=', $myref{$key}, "\n"; } }
[root@dubya perl]# cat fruit2.pl #!/usr/bin/perl $fruit{'Apple'} = "Red"; $fruit{'Orange'} = "Orange"; $fruit{'Grape'} = "Purple"; $fruit{'Lemon'} = "Yellow"; $fruit{'Lime'} = "Green"; $myHashref=\%fruit; print "Hash reference to send = $myHashref\n"; print "Print local hash\n\n"; foreach $key (sort keys %fruit) { print $key, '=', $fruit{$key}, "\n"; } print "\nLeaving Main\n\n"; &mysubrtn($myHashref); sub mysubrtn() { $myref = shift ; print "In my Subrtn\n"; print "Print hash via reference\n\n"; foreach $key (sort keys %$myref ) { print $key, '=', ${ $myref }{$key}, "\n"; } }
In reply to Passing hash reference to a subroutine by tlk00
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |