Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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,
Zaxo

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.

    -@rocks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2022-12-06 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?