Questions about this topic? Sign up to ask in the talk tab.
Difference between revisions of "Perl/Basics/Variables and Data Types/References"
From NetSec
Chantal21I (Talk | contribs) |
Chantal21I (Talk | contribs) |
||
Line 1: | Line 1: | ||
A reference is very similar to a pointer in [[C]]. | A reference is very similar to a pointer in [[C]]. | ||
+ | ====Hash References==== | ||
+ | {{:Perl/Basics/Variables and Data Types/References/Hash}} | ||
+ | |||
+ | ====Callback References==== | ||
+ | {{:Perl/Basics/Variables and Data Types/References/Callback}} |
Latest revision as of 01:58, 19 July 2012
A reference is very similar to a pointer in C.
Hash References
A hash reference is a scalar created using the \ operator as follows:
my %user; $user{'name'} = "hatter"; $user{'network'} = "irc.blackhatacademy.org"; my $hashref = \%user; |
Once you've created a hashref (hash reference) you must use pointers to access a key:
print $user->{'name'} . "\n"; print $user->{'network'} . "\n"; |
Callback References
This involves user-defined functions. User-defined functions are covered later in this article. A callback reference is a scalar that points to a function. To create a callback reference:
my $callback = \&function_name; |
To execute the callback function and pass it arguments:
$callback->($arg1, $arg2); |