function reference and ->

T

toylet

my $rf = \&{"afunction"};

I could call the function by $rf->(0) or &{$rf};

Is there a $rf->(1)?

Which chapter in perldoc should I read to learn more on this infix
thing? perlop didn't talk much.
 
T

Tassilo v. Parseval

Also sprach toylet:
my $rf = \&{"afunction"};

I could call the function by $rf->(0) or &{$rf};

Is there a $rf->(1)?

There is even a $rf->(42). They don't mean the same thing however. What
you put into the parens is passed as argument to the function referenced
by $rf. If you don't want to pass anything, call $rf->().
Which chapter in perldoc should I read to learn more on this infix
thing? perlop didn't talk much.

Probably perlref.pod.

Tassilo
 
P

pkent

toylet said:
my $rf = \&{"afunction"};

as the other poster says, you'd call this as $rf->() or $rf->($arg) or
$rf->(@args) - although I'd personally write it as:

my $rf = \&afunction;

sub afunction {
# blah
}

for what it's worth :)

P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,087
Members
48,773
Latest member
Kaybee

Latest Threads

Top