http://www.perlmonks.org?node_id=11124199


in reply to Re: Pointers and References
in thread Pointers and References

So, in answer to question 1: no, it contains a reference (which might be an address of something, but you don't {and shouldn't} need to know what).

Got it. Thanks for that clarification!

$ in Perl as a sigil means "give me a scalar value". In answer to 2: $$ means give me the scalar referred to by the scalar xxx. Because you can assign values to a scalar when you use $$ in an assignment you are assigning to the scalar referred to by the scalar. No pointers to be seen here.

Ok, I think I understand what you are saying. Taking your explanation one step further, I was wondering if I could use a "triple dollar sign" ($$$). Not that this would be idiomatic or anything but apparently you can:

my $variable = 22; my $pointer = \$variable; say "The address of \$variable, which contains the value $variable,"; say "is $pointer"; $$pointer = 25; say "Look at that! \$variable now equals $variable"; my $double_pointer = \$pointer; $$$double_pointer = 50; say "Look at that! \$variable now equals $variable";
which results in
The address of $variable, which contains the value 22, is SCALAR(0x801e64540) Look at that! $variable now equals 25 $double_pointer = REF(0x801e644b0) Look at that! $variable now equals 50
...Perl doesn't need "output parameters" because it can return multiple values from a sub.

I didn't know that! That is very cool!

References in Perl are most useful in building interesting structures which are a mixture of arrays, hashes and scalar values.

I guess I just need to keep re-reading the excellent documentation and trying this out. I implicitly understand the power of references but still struggling with applying them.