On 9/21/07, Santana <[EMAIL PROTECTED]> wrote:
> Hei all,
> 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($)
> {
> 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);
>
Probably not the best solution but this works.
!/usr/bin/perl -w
use Data::Dumper;
my %ht_state=("AL" => "Alabama","AK" => "Alaska");
sub printHT {
foreach my $f (@_) {
while((my $k,$v) = each(%$f)) {
print "$k $v\n";
}
}
}
&printHT(\%ht_state);
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
--
Rodrick R. Brown
http://www.rodrickbrown.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/