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??
Drock,

While there are several ways that you can get around creating a module and doing use Mymod, it's not really a wise thing to do for several reasons. The main reasons are:

  1. If you have a look at many of the modules on CPAN, they do a lot of strange, interesting, and sometimes evil things... internally. But since they are properly-built modules, the calling code doesn't have to worry about this. Scoping your variables properly will achieve most of this as well, but making the module is better.
  2. do "filename.pl" assumes you know the name and location of the file. use package works based on @INC, which you can change, and the package name, which you control. (Yes, the filename still comes into play, but it's a bit cleaner.) This means it works in Windows and Un*x, since you don't have to use system-specific paths/delimiters/conventions.
  3. It's kind of silly to circumvent use and require. They were designed to do what you want, and work well. C'mon! Everybody's doing it. You want to be cool, don't you? ;-)

Seriously, though, when you consider that h2xs does most of the prep work for you, making a module out of a sub is pretty much cut, paste, change a few things in the header, save, done.

--J


In reply to Re: calling perl subroutines in other files by Rhys
in thread calling perl subroutines in other files by drock

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 studying the Monastery: (4)
As of 2024-04-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found