Thousand thanks for this very valuable lesson. Some pieces of code are
always better than reading 100s of docs. I am really understanding it now.
My previous problem is what will be the difference of use inside require,
require inside use, use inside use, and require inside require. The final
ans.
I got from Jeff and some further test is this 2 .
1. Wherever the use statement(expression ?)be placed. Perl loads it
immediately
once Perl start to require/use the piece of lib/module/script FILE, no
matter you
will really using it or not.
2. Wherever the require statement places, Perl don't load it until you ask
for.
However, I am afraid that I still missed something. So please tell me if my
statements are correct or not. =)
Rgds,
Connie
>
> >When Perl read my code, if in 'use' case, would it load everything
> >existed in my modules, and won't care on how I defined the use
> >and require method in my if (...) {...} case ?
>
> Let's answer this by example. I'm going to produce several files here.
>
> ### ABC.pm
> package ABC;
>
> print "ABC\n";
>
> sub ex {
> use DEF;
> require GHI;
> print "ABC::ex\n";
> }
>
> 1;
>
>
> ### DEF.pm
> package DEF;
>
> print "DEF\n";
> 1;
>
>
> ### GHI.pm
> package GHI;
>
> print "GHI\n";
> 1;
>
> and finally:
>
> ### main.pl
> #!/usr/bin/perl
>
> print "1 main.pl\n";
>
> # use ABC;
> # require ABC;
>
> ABC::ex();
>
> print "2 main.pl\n";
>
> Once you have all these files, uncomment "use ABC" and run main.pl. You
> should get the following output:
>
> DEF
> ABC
> 1 main.pl
> GHI
> ABC::ex
> 2 main.pl
>
> If you comment "use ABC" and uncomment "require ABC", you'll get output
> like this:
>
> 1 main.pl
> DEF
> ABC
> GHI
> ABC::ex
> 2 main.pl
>
> Can you see the difference? Because ABC.pm is REQUIRE()d, Perl doesn't
> even LOOK at the file until it gets to the require() statement, and THEN
> it executes the file. But because the file has a 'use' statement in it,
> that happens AS SOON as Perl looks at the file.
>
> --
> Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
> RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
> <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
> [ I'm looking for programming work. If you like my work, let me know. ]
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]