in reply to Should we bother to save hash lookups for performance?
For a single level of indirection, as shown in your example, no. (And if you do, don't use the variables $a and $b, leave them for sort comparison functions).
On the other hand, for deeply nested hashes, yes, absolutely, assuming you're going to refer to the variable two or more times. It will make your code much more compact and easier to read.
my $bytes = $self->{center}{floor}{room}{bay}{rack}{unit}{port}{tran +smitted}; if( $bytes == 0 ) { print "Nothing transmitted.\n"; } elsif( $max < $bytes ) { $max = $bytes; } else { $sum += $bytes; } }
Keep in mind that I'm not doing this for performance reasons, I'm only concerned about readability.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Should we bother to save hash lookups for performance? (yes, sometimes)
by BrowserUk (Patriarch) on Oct 19, 2002 at 20:15 UTC | |
by Aristotle (Chancellor) on Oct 19, 2002 at 20:29 UTC | |
by BrowserUk (Patriarch) on Oct 19, 2002 at 20:59 UTC | |
by Aristotle (Chancellor) on Oct 19, 2002 at 21:05 UTC |