Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Array/Hash References? Constructors?

by bikeNomad (Priest)
on Jul 21, 2001 at 05:42 UTC ( [id://98607]=note: print w/replies, xml ) Need Help??


in reply to Array/Hash References? Constructors?

I don't know that these have catchy names. In perlref this is referred to as dereferencing a BLOCK that returns a reference. But I don't think I've ever heard anyone refer to these as such. From perlref:

2. Anywhere you'd put an identifier (or chain of identifiers) as part + of a variable or subroutine name, you can replace the identifier with a +BLOCK returning a reference of the correct type. In other words, the pre +vious examples could be written like this: $bar = ${$scalarref}; push(@{$arrayref}, $filename); ${$arrayref}[0] = "January"; ${$hashref}{"KEY"} = "VALUE"; &{$coderef}(1,2,3); $globref->print("output\n"); # iff IO::Handle is loaded Admittedly, it's a little silly to use the curlies in this case, bu +t the BLOCK can contain any arbitrary expression, in particular, subscrip +ted expressions: &{ $dispatch{$index} }(1,2,3); # call correct routine Because of being able to omit the curlies for the simple case of "$ +$x", people often make the mistake of viewing the dereferencing symbols +as proper operators, and wonder about their precedence. If they were, though, you could use parentheses instead of braces. That's not th +e case. Consider the difference below; case 0 is a short-hand versio +n of case 1, not case 2: $$hashref{"KEY"} = "VALUE"; # CASE 0 ${$hashref}{"KEY"} = "VALUE"; # CASE 1 ${$hashref{"KEY"}} = "VALUE"; # CASE 2 ${$hashref->{"KEY"}} = "VALUE"; # CASE 3 Case 2 is also deceptive in that you're accessing a variable called %hashref, not dereferencing through $hashref to the hash it's presu +mably referencing. That would be case 3.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2025-07-16 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.