Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

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!

"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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://627542]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-05-26 20:18 GMT
Find Nodes?
    Voting Booth?