[.. old posts snipped ..]

One important difference between 'use' and 'require' has to do with allowing your 
program to decide whether to include it or not.

You CAN put 'require' inside an if statement, and it will only be executed if the if 
condition is true, allowing your program to decide whether to execute the 'require' or 
not.  

if( $ThePartridgeFamilyReturnsToTV ){
    # This will only get executed in time of dire need.
    require Module::Of::Last::Resort; 
    import Module::Of::Last::Resort; 
    }

A 'use', on the other hand, is executed as part of the BEGIN block at the very start 
of your program, always, without condition.  You can put a use statement anywhere in 
your script, embedded as deeply within as many nested blocks as you like, and it's 
exactly the same as if you put it on line 1 of your script.

if( $MoonIsBlue ){
    if( $SnowstormInHell ){
        if( $DinosaursRoamTheEarth ){
            if( $MonkeysFromButtocksAreFlying ){
                use Escape::To::Alternate::Reality; # This will always get executed, 
                                                    # no matter what, 
                                                    # despite what the if
                                                    # statements lead you to think.
                }
            }
        }
    }
    
I ran across this property while working with module CGI::Simple, which starts off by 
setting STDIN to binmode, whether you actually call any functions from CGI::Simple or 
not.  All you have to do is 'use' it, and your STDIN is in binmode.  This led to some 
odd behavior when testing the program from the command line.







__________________________________________________________________
New! Unlimited Netscape Internet Service.
Only $9.95 a month -- Sign up today at http://isp.netscape.com/register
Act now to get a personalized email address!

Netscape. Just the Net You Need.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to