Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
What happens if I write a Perl module which does not end with 1;?
You could get an error.

To satisfy my curiosity, I created a contrived example to prove that an error would result with use. Since I had never experienced this in practice, it is probably difficult to achieve, but it is possible. Here is a legal (but probably unlikely) scenario. Notice that I have commented out the '1;' at the end of the package. If you uncomment it, there will be no error:

C:\Perl>type package MyFoo; use strict; use warnings; sub bar {print "bar\n"} #1; C:\Perl>type use warnings; use strict; use MyFoo; print "hello\n"; MyFoo::bar(); C:\Perl>perl did not return a true value at line 3. BEGIN failed--compilation aborted at line 3.

Since it is simple enough to do, and it is a well-known convention, it is a good practice to add '1;'.

In reply to Re: Perl Module ending without 1; by toolic
in thread Perl Module ending without 1; by prantikd

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-05-21 22:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found