in reply to Function Prototypes

If you're going to define a Perl function prototype, which is optional, by the way, then you have to define it before it gets used the first time. Otherwise, you get the message which you got. Not that getting the message is a bad thing, since you're using both '-w' and 'use strict', so you're on the right track.

Try putting your function definition of usage before it is used. It's not a bad practice to get used to.

Typically you can skip the prototype declaration for a function. It is a relatively recent introduction and prototypes are only required in a very small number of circumstances. In some cases they can make your life easier, but generally they are extraneous.

As a note, Perl function prototypes are a little different from the usual C ones:
sub func($@) { my($x,@y) = @_; }
You declare the types of variables in your specification, not what they are called. The break-out phase is separate, not unlike way old-school K&R C.

As a general procedure, I usually structure programs like:
#!/usr/bin/perl -w use strict; use VariousModules; use More::Modules; # -- Globals ------- my $style = "Round"; # -- Functions ------ sub something { my ($new_style) = @_; } # -- Main Code ------ my $thing = something($style); something_else($thing); # -- End ------------

Replies are listed 'Best First'.
Re: Re: Function Prototypes
by dragonchild (Archbishop) on Jul 03, 2001 at 16:53 UTC
    Prototypes are there only in 5.6 and higher, plus I wouldn't use them as their behavior is very ... well, un-behaved. Perl6 is s'posed to nail down the behavior of prototyping further.