Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Hash value interpolation

by ikegami (Patriarch)
on Feb 16, 2009 at 21:59 UTC ( [id://744220]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Hash value interpolation
in thread Hash value interpolation

I don't know why you have two hashes in the first place.
my %colors = ( "1" => "blue", "2" => "green", ); my $COLOR = 2; # 1..2 sub geth { print "$colors{$COLOR}\n"; } geth();

Or why you aren't using an array.

my @colors = ( "blue", "green", ); my $COLOR = 1; # 0..1 sub geth { print "$colors[$COLOR]\n"; } geth();

Replies are listed 'Best First'.
Re^4: Hash value interpolation
by csarid (Sexton) on Feb 17, 2009 at 22:44 UTC
    Thanks for all the help everyone... responding to ikegami's two points, the reason for the two hashes is because I wanted to simplify the code sample to focus on my problem, but the idea was to select a hash table to use based on a calculation. Also, the hash table makes the data elements much more readable for me. Is there a performance gained by using an array over the hash? Thanks gain!

      the reason for the two hashes is because I wanted to simplify the code

      You didn't do that. Your data structure is horribly complex. What's the point of having a hash for every key! (And don't say "1" and "2" could be the same string because then your goal makes no sense at all. There wouldn't be a right "hm" to fetch.)

      Is there a performance gained by using an array over the hash?

      Performance? Not really. The problem is that emulating a hash using an array is one more thing that can go wrong compared to just using an array.

        I see your point. I guess I can just pull the value from standard array just as easily based on the position. I'll give that a try. Thanks for the feedback do appreciate it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://744220]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-03-29 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found