Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have been away for the longest time and happened on this comment today.

A bigger issue is using &subname to call subs instead of subname() - that really doesn't do what you think it does. - in this thread Re: What to use instead of global variables

So I wondered what the difference was. I wrote the following as a SIMPLE test to see if anything jumped out at me.

#!/usr/bin/perl use strict; use warnings; 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"; } sub test2() { print "test2: Working\n"; }

When I do a "perl -c myScript.pl" I get the following

main::test2() called too early to check prototype at myScript.pl line 10. myScript.pl syntax OK

And when I run the script it seems to work with no problems. Other than I get the same warning and in the syntax check before the output. Now I do realise that I could simply remove the use warnings; from my script but I was wondering -

  1. What is the warning telling me?
  2. Also what is the difference between calling a function using &subname or subname()
  3. Where in the manual can I RTFM?
  4. Perhaps an simple example showing the different scenarios for using the different ways of calling the function


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

In reply to 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 chilling in the Monastery: (4)
As of 2024-04-20 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found