When you define your subroutine, it does not require parenthesis. Like so:
# Sub definition
sub usage {
blah...
}
# Calling the sub
usage();
You only want to use parenthesis if you want to restrict the parameters which may be sent to it. In this instance, that may be the case, but it seems as if you may have done it by accident ;-) If you do choose to use these parenthesis in the sub definition, it's called a prototype.
-Eric
Updated: As currently written, your program doesn't run because you call the subroutine using:
usage();
When you use a prototype to forbid parameters, you cannot use parenthesis in the subroutine call. You can just use:
usage;
Now, for someone better with prototypes then myself -- I know this works, because I double checked with the Camel Book before posting. But I don't know _why_ this is the case. On page 226 of Camel 3, it says that with the prototype
sub mytime(), one should call it using
mytime.
However, going back a few pages to page 222, it talks about how to call subroutines, and what the differences are. It claims that saying
foo(); passes a null list to the sub. It then says that using
foo; is the same as
foo();. Now, that can't be 100% true, if the one won't work with prototypes, but the other does. Does someone know how this is really working?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.