larr_helms has asked for the wisdom of the Perl Monks concerning the following question:

On the RIGHT SIDE of the EQUALS. WHAT does the '$$' mean?
my $frame{'Name'} = $$frm{'Name'};

Replies are listed 'Best First'.
Re: Syntax Question
by moritz (Cardinal) on Sep 14, 2009 at 14:32 UTC
    $$variable{thing} means "interpret $variable as a hash reference, dereference it and return the thing item"

    See perlreftut for more information, and for nicer ways to write it.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Syntax Question
by AnomalousMonk (Archbishop) on Sep 14, 2009 at 14:39 UTC
    It means that a hash reference is being de-referenced:
    >perl -wMstrict -le "my $frm = { foo => 11, bar => 22 }; print $$frm {bar}; print $frm ->{bar}; " 22 22
    The preferred operator for de-referencing is the  -> (arrow) operator.

    See perlref, perlreftut.

Re: Syntax Question
by Sewi (Friar) on Sep 14, 2009 at 15:17 UTC
    You could use references to make your code easier in many ways. You may know this:
    sub ShowIt { print join(',',@_); } @Foo = (1,2,3); &ShowIt(@Foo);
    Pretty easy, isn't it? But if we wan't to give two arrays, we got a problem - this isn't possible. Here we could use references:
    sub ShowIt { my $Array1 = $_[0]; my $Array2 = $_[1]; print "Array 1: ".join(',',@$Array1)."\n"; print "Array 2: ".join(',',@$Array2)."\n"; } @Foo = (1,2,3); @Bar = (4,5,6); &ShowIt(\@Foo,\@Bar);
    Here we go:
  • Foo and Bar are Arrays which are defined as usual.
  • ShowIt is called and the two Arrays are passed, but if you would pass them directly, there would be no chance to seperate which value was from which Array. They are passed as references which means: "Use the Array found at the memory location x" and references are indicated by prefixing the thing (scalar, array or hash) by a \.
  • ShowIt now puts each argument into a variable (not necessary, just for visibility)
  • The JOINs dereference (= follow the reference) the arguments. They say: Interpret the content of $Array1 as a @ (Array)
  • References make many things easier, just think of:
    @Cities_DE = ('Berlin','Hannover','Hamburg'); @Cities_US = ('New York','Miami','Las Vegas'); %Cities = ('DE' => \@Cities_DE, 'US' => \@Cities_US); print "Where are you?".join(',',@$Cities{$Country});
    You could also create references to so-called anonymus Scalars, Arrays and Hashs, but I'll leave this to the Perldoc-document...
Re: Syntax Question
by tmharish (Friar) on Sep 14, 2009 at 16:09 UTC
    From your response to the already given answers I understand that this is not what you are looking for but by itself '$$' also refers to the PID of the current process.

    use strict; use warnings; print "$$\n\n"; sleep( 100 );


    If you run the above code and then run
    ps -aef | grep "perl"
    on another window you will see this:
    UserName PID ... ... TIME Terminal TIME <Your code invocation : +perl whatever.pl>


    NOTE: This has only been tested (by me) on Unix platforms.

Re: Syntax Question
by larr_helms (Novice) on Sep 14, 2009 at 14:54 UTC
    THANKS to the individuals who replied. I understand this now.