Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: use and require inside subs

by tachyon (Chancellor)
on Nov 03, 2004 at 01:00 UTC ( [id://404801]=note: print w/replies, xml ) Need Help??


in reply to Re^2: use and require inside subs
in thread use and require inside subs

You can't hide a use like that.

if (0) { print "This block is happening!\n"; use Win32; } print "$_\n" for keys %INC; __DATA__ Exporter.pm Carp.pm strict.pm vars.pm Config.pm warnings/register.pm warnings.pm DynaLoader.pm AutoLoader.pm Win32.pm <------- Perl sees all uses (almost)

And on a system where the module is not available......

[root@devel3 root]# cat test.pl #!/usr/bin/perl -wT BEGIN{print "We are on $^O\n"} if ($^O eq 'MSWin32') { use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); # load $config from registry } else { # else load $config from flat files } [root@devel3 root]# ./test.pl We are on linux Can't locate Win32/TieRegistry.pm in @INC (@INC contains: /usr/local/l +ib/perl5/5.6.2/i686-linux /usr/local/lib/perl5/5.6.2 /usr/local/lib/p +erl5/site_perl/5.6.2/i686-linux /usr/local/lib/perl5/site_perl/5.6.2 +/usr/local/lib/perl5/site_perl) at ./test.pl line 4. BEGIN failed--compilation aborted at ./test.pl line 4. [root@devel3 root]#

cheers

tachyon

Replies are listed 'Best First'.
Re^4: use and require inside subs
by halley (Prior) on Nov 03, 2004 at 14:43 UTC
    Even more convincing is to put the print statement before the if statement.
    print "$_\n" for keys %INC; if (0) { print "This block is happening!\n"; use Win32; }

    --
    [ e d @ h a l l e y . c c ]

Re^4: use and require inside subs
by elwarren (Priest) on Nov 03, 2004 at 16:54 UTC
    hehe, so maybe I don't run that cross-platform code on other platforms recently :-) I'll have to dig it up and see what I actually did now.

    Cheers

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-05-23 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.