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 ------------

In reply to Re: Function Prototypes by tadman
in thread Function Prototypes by mvaline

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.