&foo and foo()

C

cyl

How to explain the output

&foo:123
foo():

from the script below

sub foo
{
my $x = shift;
print "$x\n";
}
sub bar
{
print "&foo:";
&foo;
print "foo():";
foo();
}

bar(123);

__END__

I can guess how it works this way but I'm wondering why? Is this
mentioned in perldoc?
 
B

Bart Van der Donck

cyl said:
How to explain the output

&foo:123
foo():

from the script below

sub foo
{
my $x = shift;
print "$x\n";
}
sub bar
{
print "&foo:";
&foo;
print "foo():";
foo();
}

bar(123);

__END__

I can guess how it works this way but I'm wondering why? Is this
mentioned in perldoc?

&foo; is the only notation where the current arguments are passed to
the foo-subroutine without need to mention them in ().

Search http://perldoc.perl.org/perlsub.html for 'get current args'
(e.g. with CTRL-F on that page).
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top