[sf-perl] dynamic use command

Michael Friedman friedman at highwire.stanford.edu
Fri Apr 4 16:04:51 PDT 2008


I'd been waiting to try it out before replying, but it seems to work  
for 'use strict' at least.

However, since the special directives (non-modules) that go with 'use'  
don't actually get a default BEGIN block, there's no need to use  
require and import. You can


... bad code ...

use strict;

... good code ...

no strict;

... bad code ...


as much as you want.

-- Mike

On Apr 4, 2008, at 3:57 PM, Quinn Weaver wrote:
> On Fri, Apr 04, 2008 at 03:04:15AM -0800, Rich Morin wrote:
>> At 00:17 -0700 4/4/08, Michael Friedman wrote:
>>> The other thing you can do is realize that, according to
>>> `perldoc -f use`:
>>>
>>> 	It [use] is exactly equivalent to
>>>       	BEGIN { require Module; import Module LIST; }
>>
>> Is this true in the case of "use strict"?
>
> I think so.  Take a look at the strict.pm source code:
>
> vi `perldoc -l strict`
>
> There's a 'sub import' in there which seems to set strict refs and/ 
> or subs
> and/or vars according to what you write in 'use strict LIST'.
>
> -- 
> Quinn Weaver, independent contractor  |  President, San Francisco  
> Perl Mongers
> http://fairpath.com/quinn/resume/     |  http://sf.pm.org/
> 510-520-5217
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm

---------------------------------------------------------------------
Michael Friedman                     HighWire Press
Phone: 650-725-1974                  Stanford University
FAX:   270-721-8034                  <friedman at highwire.stanford.edu>
---------------------------------------------------------------------




More information about the SanFrancisco-pm mailing list