Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Defining Subroutines

by Zaxo (Archbishop)
on Oct 24, 2002 at 03:02 UTC ( #207613=note: print w/replies, xml ) Need Help??

in reply to Defining Subroutines

You got it backwards. Define a function with sub. You can call it with &max, but it's better to call using parentheses until you're comfortable with what the ampersand does. It causes prototypes to be ignored, and it arranges for the function to be called with the existing @_ as arguments.

After Compline,

Replies are listed 'Best First'.
Re: Re: Defining Subroutines
by rir (Vicar) on Oct 24, 2002 at 04:11 UTC
    Not quite, using the ampersand causes the routine call to use the existing @_ as the default arguments. If you provide arguments they are used instead.
    sub z { my $i =1; foreach (@_) { print "$i : $_\n"; $i++; } } sub x { &z; # 1 &z( "good", "bye"); &z; # same as one again &z(); # called with empty list } x( "say", "hello");
Re^2 Defining Subroutines
by @rocks (Scribe) on Oct 24, 2002 at 04:40 UTC
    Ok Zaxo, Thank you very much for the information. I got it now, thank you.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://207613]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2023-12-11 03:52 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.