Meaningless Drivel is fun!
The moose likes Other Languages and the fly likes What is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "What is "$$" for?" Watch "What is "$$" for?" New topic

What is "$$" for?

Allen Chan
Ranch Hand

Joined: Jun 07, 2002
Posts: 64
Hi all,
I know this is not the place, but what is "$$" for in perl, a line reads $str = "this" ."$$ADS{'name'}";
Allen Chan
Ranch Hand

Joined: Jun 07, 2002
Posts: 64
man, you go extra extra miles for my questions, thanks a ton
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
I suppose the closest point to post this would be here
Your question involves Using Hard References. If this is your first encounter to them, it will be a bit tough to grasp them the first time. (I have read it about five times, until they started to make sense, but afterwards its quite rewarding :cool
The '$' in Perl refers to a scalar variable, if there is more then one '$' they are parsed from right to left:
is equivalent to ${${${var}}}
In English, you would interoperate that as:
$var is a scalar ref variable(1) which points to an anonymous scalar ref variable(2) which points to another anonymous scalar ref variable(3). Whew, what a mouthful!
So let's focus on:

First of all, the quotes around the name KEY is not necessary, unless the KEY has spaces in it, $hash{ KEY } is the same as $hash{KEY}.
From the code, you infer that $ADS is an anonymous hash that is most likely composed on the fly where your reference variable springs into existence (in Perl jargon you say they autovivify). The $ADS hash can also be set explicitly as in:

The {... } is the anonymous hash composer. To access any value you dereference it as $$hashref{KEY}.
You can also use any of these:
I prefer the last one for its clarity.
Here is some more food for thought (if you have a *nix OS)

Results in the following:

2:$ADS is a reference
4:$ADS{name} is not a reference
5:Bob Smith
6:Bob Smith

Hope this helps�

Normal is in the eye of the beholder
I agree. Here's the link:
subject: What is "$$" for?
It's not a secret anymore!