http://qs321.pair.com?node_id=207613


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