in reply to Enforcing formal arguments at compile time?
#!/usr/bin/perl use strict; sub foo($); #declare foo as a sub that accepts #a single scalar, to be defined later foo; #compile time error foo 1; #okay - no error sub foo($) { #actual foo implementation print shift; }
Update: tachyon rightly points out that this won't always behave as expected - and gives two good links for reference. Perl tries to figure out the context of your arguments, which may (or may not) DWIM.
sub foo($$); #two scalar arguments foo $bar; #error foo @bar; #error foo $bar, $baz; #ok foo $bar, @baz; #no error, but does it do what you want?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Enforcing formal arguments at compile time?
by tachyon (Chancellor) on May 03, 2002 at 05:28 UTC | |
by pdcawley (Hermit) on May 03, 2002 at 11:44 UTC | |
by tachyon (Chancellor) on May 03, 2002 at 12:07 UTC | |
by pdcawley (Hermit) on May 03, 2002 at 15:52 UTC |