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

What does $$ \@ \$ do? I'm still a bit of a perl newbie. :)

Replies are listed 'Best First'.
Re: A few questions
by btrott (Parson) on May 09, 2000 at 20:37 UTC
    From perlvar, $$ is the process ID of the perl running your script.

    With regards to \@ and \$: I'm assuming that you're talking about something like:

    my $array_ref = \@array; my $hash_ref = \%hash;
    Is that the case?

    What's happening there is that you're taking a reference to an array and a hash. References are described in perlref. They're kind of like C pointers, but also kind of not. :)

    References are scalars that "point" to other variables--the other variables can be arrays, hashes, scalars, etc. To use the variable pointed to by a reference, you have to dereference the reference. This could also be what you were referring to by $$, because if we had a reference to a scalar, like this:

    my $string = "foo bar"; my $ref = \$string;
    then we could get access to the value "foo bar" by dereferencing $ref, like this:
    my $original = $$ref;
    $original now contains "foo bar".

    So take a look at perlref and also at perlreftut, which might actually be a better place to start than perlref, depending on your experience.

Re: A few questions
by raflach (Pilgrim) on May 09, 2000 at 21:34 UTC
    Note that $$ by itself is the process ID of your current process. Usefull in combination with other semi-random numbers for better randomization routines, and for Inter-process communication.
Re: A few questions
by zodiac (Beadle) on May 10, 2000 at 16:11 UTC
    \@ is usefull if you need an array of arrays. eg:
    my @x = (1, 2, 3, 4); my @y = ();
    and
    push @y, \@x;
    instead of
    push @y, @x;
    because the later will push the elements of @x onto @y, not @x itself. the same is true for \% of cause. to get the array out of the array of arrays again:
    $z = pop @y; @x = @{$z}; # or @$z

    for more information on "strange" looking variables look at man perlvar and man perldata