For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2005 > Doubt in Data Structure Hash of Arrays!!!!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Doubt in Data Structure Hash of Arrays!!!!
asha

2005-01-06, 11:32 pm

Hi,

I am getting some errors. I am not able to figure that out. I feel the code is right.I am passing an array into a subroutine and building a hash depending upon the values( grouping index with common values).

I see that some of the values are not stored in the array while printing it. I am pasting that section of code here.


my($ent) = @_;
my %assos= ();

my @e = @$ent;

no strict 'refs';
my $i = -1;
foreach my $ev (@e){
$i++;
if(exists($assos{$ev})){
#here the value '0' '2' '4' '11' etc are not pushed but its entering the loop
push @{$assos$ev}},"$i";
print("@{$assos{$ev}}\n");
} else{
$assos{$ev} = "$i";
print(" @{$assos{$ev}}\n");
}
}

foreach my $ev ( keys %assos ) {
print "$ev: @{ $assos{$ev} }\n";}


Can anyone of you let me know what went wrong. and how to solve it.

Thank You

Asha
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com