On Aug 8, Brent Clark said:
Would someone be so kind to explain the following code.
my $subclasses = { 'rejects' => \&_reject_html,
'deferrals' => \&_deferral_html,
'errors' => \&_error_html,
'deliveries' => \&_delivery_html,
'unknown' => \&_unknown_html,
'queue' => \&_queue_html };
Would someone please share some info on why \& and not just &?
If you wrote:
my $subclasses = {
rejects => &_reject_html,
...
};
then the values in the %$subclasses hash would be whatever was returned by
the _reject_html() function. The \&function construct produces a
reference to a subroutine (like you wrote in your subject!) that enables
us to *call* the function at a later time.
my %dispatch_table = (
this => \&abc,
that => \&def,
...
);
if (my $code = $dispatch_table{$state}) {
$code->(@arguments);
}
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>