> Hi, > > The following code is hanging up the browser and I think it has something > to do with the hash having keys array and values array. There is no error > message, just the browser taking a really long time. Any help would be > appreciated. Works fine with 3 line, 12 word 1 kb text file but not with 7 > kb text file. >
This is a lot of code to walk through (for me) at this time, and the fact that you are declaring your variables up front rather than during the first use prevents 'strict' from giving you much assistance and *may* be leading to your problem, I am not saying that it does for sure. I would suggest reworking your code to declare your variables at the time you use them rather than at the top. Additionally you may consider moving your subs to a library file to double check you haven't broken encapsulation (because you have, $file as a global guarantees it), this *could* also be leading to your problem. Having said that if someone else doesn't spot your issue first, I will take a look at it closer tonight and see if I can't spot it. > #SNIP_OF_CODE_WHERE_HANGING_UP_BROWSER > my %uniqueHash = (); > my @uniqueArray; > my @countsArray; > @[EMAIL PROTECTED] = @countsArray; > What do you think the above line is doing? @countsArray and @uniqueArray are both empty. > > for my $word (sort sort_values keys %uniqueHash) > { > $percentage = $uniqueHash{$word}/($totalcount); This is a good example of what I meant by declaring your variables when you use them. $percentage should have the scope of this loop but is scoped at least one level up (and maybe two) which makes your code much more confusing. > printf "%-15s %5d %5.3f \%\n", "$word", $uniqueHash{$word}, $percentage*100; > if ($uniqueHash{$word} >= $mostvalue) > { > $mostvalue = $uniqueHash{$word}; > $mostArray[$count] = $word; > $mostValues[$count] = $uniqueHash{$word}; > $mostHash{$mostArray[$count]} = $mostValues[$count]; > $count++; > } > } > > sub sort_values { $uniqueHash{$b} <=> $uniqueHash{$a} } > #SNIP_END > You might also want to look into Data::Dumper, perldoc Data::Dumper And see if it will show you precisely what is in some of your hashes and arrays, you may be confused about what they actually contain. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>