in reply to Modules, Prototypes, and References

In the first case (without making a module), it sounds like the prototype does not appear in the source code before the call(s) to the subroutine. This prevents the prototype from having any effect on those calls and explains why your incorrect calls (given the prototype) are not being flagged as incorrect.

A "\$" in a sub prototype means that the caller is supposed to type $var and Perl converts that to have the same effect as if the caller had typed \$var. The caller typing \$var would cause a compile-time error (if the prototype were in effect).

The easiest way to "fix" the first case is to put:

sub DoSomething( $\$\$ );
(note the semicolon) near the top or your script and then drop the \'s in your calls to DoSomething.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Modules, Prototypes, and References
by dkusters (Initiate) on Feb 01, 2001 at 23:28 UTC
    Ah... so I wasn't using prototype correctly. Thanks!