Call a function: Difference between revisions

Perl - Updated for more correctness, legibility
(added R)
(Perl - Updated for more correctness, legibility)
Line 1,090:
 
=={{Header|Perl}}==
The most common syntax; simply calls the function foo on the argument(s) provided.
<lang perl>foo();
<lang perl>foo(); # Call foo on the null list
&foo('foo', 'bar'); # Older style syntax with explicit sigil
&foo(); # Bareword syntax only works after the function declarationDitto
foo 'foo'($arg1, 'bar'$arg2); # AsCall foo on a$arg1 listand operator$arg2
&foo($arg1, $arg2); # Ditto; ignores prototypes</lang>
 
Call foo() as a bareword. Only works after the function has been declared, which
# Coderef syntax, for references obtained by assigning a subroutine to a
#can scalarbe ordone bynormally taking a referenceor with the \use subs operatorpragma.
<lang perl>foo();</lang>
&$fooref('foo', 'bar');
Call foo() with the current values of @_<lang perl>&foo;</lang>
Call foo() with the current values of @_, discarding the previous stack frame. Not your grandfather's (harmful) goto, although the keyword can do both.<lang perl>goto &foo;</lang>
For subroutines stored in references (anonymous subroutines).<lang perl>&$fooref('foo', 'bar');
&{$fooref}('foo', 'bar');
$fooref->('foo', 'bar');</lang>
Anonymous user