Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

What does " => \& " mean?

Quote Reply
What does " => \& " mean?
Could someone explain the meaning of this. It appears in so many places.

as in:
CategoryID => \&build_category_row,

Also, does anyone know how to pass a variable along with it, or is it even possible to say
something like

CategoryID => \&build_category_row($DATABASE)

Thanks in advance and sorry for the mundane question.

Kyle
Quote Reply
Re: What does " => \& " mean? In reply to
hi klangan..

Code:
CategoryID => \&build_category_row,

makes the key $hash{CategoryID} with the value of a reference CODE.. this is used in build_html_record_form.. if you were to put in data.. it would mess up all the Category IDs..

build_html_record_form automatically does that with the name, value, and the record..

------------------
Jerry Su
Links SQL Licensed
------------------
Quote Reply
Re: What does " => \& " mean? In reply to
Hi Kyle,

As widgetz said, it's setting the 'CategoryID' key equal to a CODE reference. If you had:

sub foo {
print "Hello!";
}

and:

$a = \&foo;

Then $a is a code reference to the subroutine foo. And if you did:

&$a

it would run the subroutine foo and print out the text. You can't do:

$a = \&foo("some value");

but rather you want to do:

&{$a}("some value");

as parameters are passed when you call the subroutine, and can't be saved.

Hope that helps,

Alex