From: John Kelly on 23 Jun 2010 08:28 > use YourModule; > This imports all the symbols from YourModule's @EXPORT > into the namespace of the use statement. > use YourModule (); > This causes perl to load your module but does not import any symbols. Specifying () every time seems safe, but a hassle. Without reading the source, can I get a list of default export symbols for a module? -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php
From: Tad McClellan on 23 Jun 2010 08:57 John Kelly <jak(a)isp2dial.com> wrote: > >> use YourModule; >> This imports all the symbols from YourModule's @EXPORT >> into the namespace of the use statement. > >> use YourModule (); >> This causes perl to load your module but does not import any symbols. > > Specifying () every time seems safe, but a hassle. In _my_ cost/benefit analysis, typing 2 characters in return for safety wins... > Without reading the > source, can I get a list of default export symbols for a module? Errr, yes, by printing out the contents of the array mentioned in the docs you quoted: perl -MCarp -le 'print for @Carp::EXPORT' -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: Peter Makholm on 23 Jun 2010 09:43 John Kelly <jak(a)isp2dial.com> writes: >> use YourModule (); >> This causes perl to load your module but does not import any symbols. > > Specifying () every time seems safe, but a hassle. Without reading the > source, can I get a list of default export symbols for a module? Some modules (ab)uses the import() methods for other things than polluting your symbol table. These modules might work differently. This is partly documented in 'perldoc -f use': If you do not want to call the package's "import" method (for instance, to stop your namespace from being altered), explicitly supply the empty list: use Module (); That is exactly equivalent to BEGIN { require Module } If the VERSION argument is present between Module and LIST, then the "use" will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable $Module::VERSION. Again, there is a distinction between omitting LIST ("import" called with no arguments) and an explicit empty LIST "()" ("import" not called). Note that there is no comma after VERSION! //Makholm
From: John Kelly on 23 Jun 2010 10:02 On Wed, 23 Jun 2010 07:57:53 -0500, Tad McClellan <tadmc(a)seesig.invalid> wrote: >>> use YourModule (); >>> This causes perl to load your module but does not import any symbols. >> Specifying () every time seems safe, but a hassle. >In _my_ cost/benefit analysis, typing 2 characters in return >for safety wins... I meant it's a hassle to package qualify every symbol I want to use. I like writing terse code with short names. So if a package doesn't step on my names, I may want its symbols in main. It would be nice if there was a warning when package symbols step on symbols already in main. > perl -MCarp -le 'print for @Carp::EXPORT' I'll try that. Thanks for the tip. -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php
|
Pages: 1 Prev: FAQ 4.20 How do I unescape a string? Next: who stole my returned list? |