Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: right use of a hash table

by injunjoel (Priest)
on Jul 19, 2007 at 15:27 UTC ( #627542=note: print w/ replies, xml ) Need Help??


in reply to right use of a hash table

steph_bow,
You are initializing a scalar $M4 yet you are using it like a hash %M4 with your $M4{$target} code. You are saying give me the scalar ($) in the %M4 hash at the key $target, whatever that happens to be. Though a hash is initialized with the % symbol it contains scalars as values. Thus when you refer to an element in the hash (be it a number, string, character or reference to something else) you call it in its resultant context, in this case a scalar (though you could also pull out an array or another hash if that is what you stored a reference to in there) . If you want to use a scalar as a reference to an anonymous hash you would need to change your assignments to utilize the -> so $M4_compteur{$target} becomes $M4_compteur->{$target} for both assignment and retrieval. Does that make sense?
perldata, perldsc and perlref might all be of help. Happy reading!

-InjunJoel

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo


Comment on Re: right use of a hash table
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2015-07-05 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls