Making references
References can be created in several ways.
By using the backslash operator on a variable, subroutine, or value. (This works much like the & (address-of) Operator in C.) This typically createsAnotherReference to a variable, because there's already a reference to the variable in the symbol table. but the symbol table reference might go away, and you'll still have the reference that the backslash returned. here are some examples:
- $scalarref = \$foo;
- $arrayref = \@ARGV;
- $hashref = \%ENV;
- $coderef = \&handler;
- $globref = \*foo;
Using references
That's it for creating references. By now you're probably dying
Know how to use references to get back to your long-lost data. There
Are several basic methods.
- Anywhere you 'd put an identifier (or chain of identifiers) as part of
Variable or subroutine name, you can replace the identifier with
Block returning a reference of the correct type. In other words,
Previous examples cocould 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