vendredi 14 novembre 2014

Perl - Reverse sorting a hash table missing the first value in it


Vote count:

0




So i had yesterday posted a question about a regex regarding hyphens, and i proceeded to use this regex pattern:



$comparator =~ s/(?!-)[[:punct:]]//g;


And all was well. I was chomping the comparator as soon as it was read-in, applying that regex pattern to the strings in the file that were being read in, applying a loop like this:



foreach my $comparison(split /\s+/, $comparator)


and then adding those values to a hashtable with a %hash($word++). Next i proceeded to do a sorting comparison to print out the first 25 values from greatest to lowest occurence and used this



foreach my $key (sort { $hash{$a} <=> $hash{$b} } keys %hashes) { if the value is less than 25, print them: }


It proceeds to print them, however my first value always is blank, so the output would be something like


First value, occurs 5000 times


Second value, cue, occurs 2300


Third value, darling, occurs 1200


Could anyone tell me why my first value is always blank? am i doing something wrong? I have pretty much psudocode described my algorithm. Any help would be appreciated, thanks



asked 2 mins ago







Perl - Reverse sorting a hash table missing the first value in it

Aucun commentaire:

Enregistrer un commentaire