Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: calling perl subroutines in other files

by Rhys (Pilgrim)
on Sep 26, 2004 at 12:11 UTC ( #393929=note: print w/replies, xml ) Need Help??

in reply to calling perl subroutines in other files


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 "" 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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393929]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2021-03-02 08:48 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (41 votes). Check out past polls.