in reply to Correct idiom for default parameters
Here's one way (requires 5.10+). You'll decide for yourself if it is any better:
sub test{ my $p1 = shift // 1; my $p2 = shift // 2; my $p3 = shift // 3; print "p1:$p1; p2:$p2; p3:$p3"; };; test();; p1:1; p2:2; p3:3 test( 'a' );; p1:a; p2:2; p3:3 test( 'a', 'b' );; p1:a; p2:b; p3:3 test( 'a', 'b', 'c' );; p1:a; p2:b; p3:c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Correct idiom for default parameters
by Anonymous Monk on Apr 29, 2010 at 07:41 UTC | |
by BrowserUk (Patriarch) on Apr 29, 2010 at 10:51 UTC |