http://qs1969.pair.com?node_id=404801


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