Santana wrote:
Hei all,
Hello,
how print a hashtable elements in a function that receives the reference of this hastable ??? In this example this foreach loop in "printHT" function dont work , how is missed ? #!/usr/bin/perl use strict; use warnings; sub printHT($)
You are using a prototype. You shouldn't use prototypes. http://library.n0i.net/programming/perl/articles/fm_prototypes/
{ my $T =$_[0]; foreach my $id (keys (%$T)){ #This dont work :) print $$T{$id} . "\n"; } } my %ht_state=("AL" => "Alabama","AK" => "Alaska"); &printHT(\%ht_state);
The ampersand in front of the subroutine name means that the prototype will be ignored. You shouldn't use an ampersand in front of a subroutine name.
perldoc perlsub Your code works for me: $ perl -e' use strict; use warnings; sub printHT($) { my $T =$_[0]; foreach my $id (keys (%$T)){ #This dont work :) print $$T{$id} . "\n"; } } my %ht_state=("AL" => "Alabama","AK" => "Alaska"); &printHT(\%ht_state); ' Alabama Alaska John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/