Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: right use of a hash table

by injunjoel (Priest)
on Jul 19, 2007 at 15:27 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-28 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found