
eagle
New User
May 23, 2010, 3:23 AM
Post #1 of 5
(4950 views)
|
Loop only throw part of Hash // prevent sort problems
|
Can't Post
|
|
Hi all, I tried to find a solution by extensive googling, but didn't get a good solution so far. Problem: I run throw big files and save hits in a big hash file. Acccording to the files name, they are saved as %bighash{hitname}{filename} whereas scores are subclassed as %bighash{hitname}{filename}->{score}. This means that lateron, I get a big hash with 'hitname' entries that do not contain entries for all the files. I wanna sort then the enrtries coming from only one file by using a code as follows:
foreach $value (sort {$targets{$b}{'filename'}->{'aggpval'} <=> $targets{$a}{'filename'}->{'aggpval'} } keys %targets ) { $j++; if ( $j <= 50 ) { print "$j: $value ". $targets{$value}{'filename'}->{'aggpval'} ."\n"; } } The problem is then that for some keys of the hash, the subhash is not defined and perl grumbles since the sort is supposed to sort non defined values. Is there a way to exclude the not defined parts of the hash properly? ideally, i would like to have a sort that would follow this logics: foreach $value ( sort ... ) keys %hash{.*}{'filename'} i found some hints about hash slices etc, but i would like to keep all the entries within one big hash for different reasons... (by the way, i know that i should rather leave the loops when reaching 50 instead of looping throw the whole thing) thanks a lot for any help
|