Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

autouse vs use

by kiat (Vicar)
on Apr 25, 2005 at 03:31 UTC ( [id://451085]=perlquestion: print w/replies, xml ) Need Help??

kiat has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Is Method 2 generally preferred over Method 1 when using methods from another module? If so, what are the reasons?

# Method 1 use Mymodule qw(&func1 &func2); # Method 2 autouse Mymodule => qw(func1 func2);
Thanks in advance:)

Updated: Method 2 should have been:

use autouse Mymodule => qw(func1 func2);
Thanks to perrin for pointing out.

Replies are listed 'Best First'.
Re: autouse vs use
by jasonk (Parson) on Apr 25, 2005 at 03:41 UTC

    Generally I would recommend against autouse unless you really know why you need it. There are some big caveats that are covered in the documentation about how it could break your application. The shorter answer is that it depends on what 'Mymodule' does (if the module you are autousing has initialization that it expects to occur early, it will break).


    We're not surrounded, we're in a target-rich environment!
Re: autouse vs use
by perrin (Chancellor) on Apr 25, 2005 at 05:16 UTC
    I think your syntax is wrong:
    use autouse Mymodule => qw(func1 func2);
    The autouse module was only recently added to the perl core and I've personally never seen anyone use it for anything, but the purpose is to avoid loading a large module if it isn't needed. This is probably mostly interesting for CGI scripts where startup speed is very important. You can do the same thing for simple cases, minus the import, just by calling require() before calling the function you want.
      This is probably mostly interesting for CGI scripts where startup speed is very important.

      Note that persistent environments, like mod_perl or FastCGI, actually want to pre-load as much as possible. In those contexts, this reduces startup speed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://451085]
Approved by moot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-03-29 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found