Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: hash reference doubt

by targetsmart (Curate)
on Jul 20, 2009 at 09:51 UTC ( #781578=note: print w/ replies, xml ) Need Help??


in reply to Re: hash reference doubt
in thread hash reference question

I know that it is deprecated, I never used this %hash->{key}, I came across some code like that, wanted to understand how it works; for my knowledge.
my question is, I can understand what is going on when I do $hash{key}, but I can't understand what is going when I do %hash->{key}, kindly explain.


Vivek
-- 'I' am not the body, 'I' am the 'soul', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.


Comment on Re^2: hash reference doubt
Re^3: hash reference doubt
by davorg (Chancellor) on Jul 20, 2009 at 10:05 UTC

    What is going on is that Perl is exposing more of its internals than it really should be. The name of the hash is being interpreted like a reference when you use this syntax.

    %hash->{key} should never have worked, but some people noticed that it did and (wrongly) started to use it. And that's why it's just deprecated and hasn't been removed from the language yet.

    --

    See the Copyright notice on my home node.

    Perl training courses

Re^3: hash reference doubt
by CountZero (Bishop) on Jul 20, 2009 at 13:53 UTC
    but I can't understand what is going when I do %hash->{key}, kindly explain
    There is nothing to understand or explain, other than that %hash->{key} should have triggered a syntax error in Perl. Some older Perls didn't and therefore this error was downgraded to a warning to avoid breaking existing scripts.

    A reference should always be a scalar (which can be part of an array, a hash or indeed an object or the return value of a subroutine, but not the array, hash, ... itself.

    BTW you will trigger a similar warning with the following:

    @array = qw /1 2 3 4 5/; print @array->[1];
    It really is the same issue.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-31 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (251 votes), past polls