chinman has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
Let me first say that this site rocks! I'm a Perl newbie and have found the information here to be extremely useful in learning Perl.
Right, then! I've got a hash of x,y data (mass = keys,intensities = values). In my script, I search for a mass key that represents the largest intensity within a window of +- 0.3 mass units. I've populated my hash with mass data to the nearest 0.1 units. Is there anyway to extract the keys matching the tolerance without the for loop. I'm doing lots of these calls in my script, so any speed gained here would be helpful. Cheers!
#subroutine that gets the largest intensity of the mass ($_[0] #within a mass tolerance window of +- 0.3. sub getIntensity { my $mLo = $_[0] – 0.3; my $mHi = $_[0] + 0.3; my $intensity = 0; for ( my $i = $mLo; $i <= $mHi; $i += 0.1 ) { $i = sprintf("%.1f", $i); if ( exists $massint{ $i } ){ if ( $massint{ $i } > $intensity ){ $intensity = $massint{ $i } } } } return $intensity; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: speeding up a hash lookup
by arturo (Vicar) on Mar 27, 2001 at 20:50 UTC | |
Re: speeding up a hash lookup
by japhy (Canon) on Mar 28, 2001 at 01:31 UTC | |
Re: speeding up a hash lookup
by jeroenes (Priest) on Mar 27, 2001 at 21:13 UTC | |
Re: speeding up a hash lookup
by physi (Friar) on Mar 27, 2001 at 21:00 UTC | |
Re: speeding up a hash lookup
by jbert (Priest) on Mar 27, 2001 at 22:19 UTC | |
Re: speeding up a hash lookup
by MeowChow (Vicar) on Mar 27, 2001 at 22:09 UTC | |
Re: speeding up a hash lookup
by chinman (Monk) on Apr 01, 2001 at 03:00 UTC |
Back to
Seekers of Perl Wisdom