Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So I found that if I change the code to the following I no longer get the warning,
#!/usr/bin/perl use strict; use warnings; sub test2() { print "test2: Working\n"; } print "About to test sub calls using \& --\n"; &test1; print "About to test sub call using name() --\n"; test2(); sub test1() { print "test1: Working\n"; }

So I have to declare the function before I call it.

"(W prototype) You've called a function that has a prototype before the parser saw a definition or declaration for it, and Perl could not check that the call conforms to the prototype. You need to either add an early prototype declaration for the subroutine in question, or move the subroutine definition ahead of the call to get proper prototype checking. Alternatively, if you are certain that you're calling the function correctly, you may put an ampersand before the name to avoid the warning."

So I guess that answers Question 1. Thanks Perlmonks!

I guess the comment in italics also explains the use of the & then.

Bah!! I also added use diagnostics; and got the above mentioned paragraph.. it also told me to read perlsub

So I guess that answers 3 of the 4 questions and I bet that reading perlsub I'll clearly see the reasons you need &subname as apposed to subname()

Sorry for posting this too quickly!

Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: Calling Functions by AcidHawk
in thread Calling Functions by AcidHawk

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found