Professional Web Applications Themes

Use and Require - PERL Beginners

Dear Perl Gurus, What is the difference between Use and Require. Thanks, Malliks...

Sponsored Links
  1. #1

    Default Use and Require

    Dear Perl Gurus,

    What is the difference between Use and Require.

    Thanks,
    Malliks
    Sponsored Links
    Mallik Guest

  2. #2

    Default Re: Use and Require

    Mallik wrote:
    >
    > What is the difference between Use and Require.
    See

    perldoc -f use
    perldoc -f require

    Why do you ask?

    /R


    Rob Dixon Guest

  3. #3

    Default Re: Use and Require

    For Quality purpouses, Mallik 's mail on Thursday 29 January 2004 18:57 may
    have been monitored or recorded as:
    > Dear Perl Gurus,
    that must be someone else
    >
    > What is the difference between Use and Require.
    >

    try perldoc -f use on your box (or [url]www.perldoc.com):[/url]

    use Module VERSION LIST
    use Module VERSION
    use Module LIST
    use Module
    use VERSION
    Imports some semantics into the current package
    from the named module, generally by aliasing cer-
    tain subroutine or variable names into your pack-
    age. It is exactly equivalent to

    BEGIN { require Module; import Module LIST; }

    except that Module must be a bareword.

    VERSION may be either a numeric argument such as
    5.006, which will be compared to $], or a literal
    of the form v5.6.1, which will be compared to $^V
    (aka $PERL_VERSION. A fatal error is produced if
    VERSION is greater than the version of the current
    Perl interpreter; Perl will not attempt to p
    the rest of the file. Compare with "require",
    which can do a similar check at run time.

    There is tons more infomation of how use/require are simliar/different.

    Enjoy. Wolf



    Wolf Blaum Guest

  4. #4

    Default Re: Use and Require

    > Mallik wrote:
    > >
    > > What is the difference between Use and Require.
    >
    > See
    >
    > perldoc -f use
    > perldoc -f require
    >
    > Why do you ask?
    >
    > /R
    >
    >
    Wow such a civilized answer. Some would say...

    S R Q I R E

    This is such a nice list.

    Time to revisit: [url]http://www.catb.org/~esr/faqs/smart-questions.html[/url]

    [url]http://danconia.org[/url]
    Wiggins D Anconia Guest

  5. #5

    Default RE: Use and Require

    > > Mallik wrote:
    > > >
    > > > What is the difference between Use and Require.
    > >
    > > See
    > >
    > > perldoc -f use
    > > perldoc -f require
    > >
    > > Why do you ask?
    > >
    > > /R
    > >
    > >
    >
    > Wow such a civilized answer. Some would say...
    >
    > S R Q I R E
    Who is Senior Qire?
    >
    > This is such a nice list.
    >
    > Time to revisit: [url]http://www.catb.org/~esr/faqs/smart-questions.html[/url]
    Dan Muey Guest

  6. Moderated Post

    Default Re: Use and Require

    Removed by Administrator
    Jan Eden Guest
    Moderated Post

  7. #7

    Default Re: Use and Require


    On Jan 29, 2004, at 9:57 AM, Mallik wrote:
    [..]
    > What is the difference between Use and Require.
    [..]

    The easiest way to think about it was that
    once upon a time we wanted to have 'functions'
    that would be in 'perl libraries' - so there
    needed to be a directive that indicated that
    the code 'required' certain things - such as
    a minimum version of perl, or a named perl library.

    the idea of the 'use Foo::Bar' on the other hand
    is about indicating that the perl compiler merely
    need to know that we will be using a perl Module
    that is external to this file and that it will

    a. look for Bar.pm in some sub_directory Foo
    that is in the INC path

    b. either directly invoke the 'import()' method
    of that module - or invoke it with a list of
    tokens that will be imported...

    So as the other person noted,

    What exactly are you interested in knowing about them?


    ciao
    drieux

    ---

    Drieux Guest

  8. #8

    Default Re: Use and Require

    In article <NHBBLNCADDJDFAFMNFMMCEGPCFAA.mallikarjunksoftima .com>,
    [email]mallikarjunksoftima.com[/email] (Mallik) writes:
    >Dear Perl Gurus,
    >
    >What is the difference between Use and Require.
    use Foo;

    is equivalent to:

    BEGIN {
    require Foo;
    Foo->import;
    }

    --
    Peter Scott
    [url]http://www.perldebugged.com/[/url]
    *** NEW *** http//www.perlmedic.com/
    Peter Scott Guest

  9. #9

    Default Re: Use and Require

    [.. 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 [url]http://isp.netscape.com/register[/url]
    Act now to get a personalized email address!

    Netscape. Just the Net You Need.
    mcdavis941@netscape.net Guest

  10. #10

    Default Re: Use and Require

    Wiggins D Anconia wrote:
    >>Mallik wrote:
    >>
    >>>What is the difference between Use and Require.
    >>
    >>See
    >>
    >> perldoc -f use
    >> perldoc -f require
    >>
    >>Why do you ask?
    >>
    >>/R
    >>
    >>
    >
    >
    > Wow such a civilized answer. Some would say...
    >
    > S R Q I R E
    >
    > This is such a nice list.
    >
    > Time to revisit: [url]http://www.catb.org/~esr/faqs/smart-questions.html[/url]
    >
    > [url]http://danconia.org[/url]
    I still don't get: S R Q I R E

    : )
    Robert Guest

  11. #11

    Default Re: Use and Require

    Robert wrote:
    > Wiggins D Anconia wrote:
    >
    >>> Mallik wrote:
    >>>
    >>>> What is the difference between Use and Require.
    >>>
    >>>
    >>> See
    >>>
    >>> perldoc -f use
    >>> perldoc -f require
    >>>
    >>> Why do you ask?
    >>>
    >>> /R
    >>>
    >>>
    >>
    >>
    >> Wow such a civilized answer. Some would say...
    >>
    >> S R Q I R E
    >>
    >> This is such a nice list.
    >> Time to revisit: [url]http://www.catb.org/~esr/faqs/smart-questions.html[/url]
    >>
    >> [url]http://danconia.org[/url]
    >
    >
    > I still don't get: S R Q I R E
    >
    > : )
    >
    Use, require.. each has a u and e, subtract them, and you are left with
    '.s.' and 'r.q.ire'... ok so it was a bad joke, it wasn't much of a
    question either....

    [url]http://danconia.org[/url]
    Wiggins D'Anconia Guest

Similar Threads

  1. require
    By Tom in forum PHP Development
    Replies: 2
    Last Post: April 12th, 02:49 PM
  2. #25782 [Opn->Bgs]: require( 'require.php' ) crashing Apache 1.3.28
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: October 13th, 02:33 AM
  3. #25782 [Fbk->Opn]: require( 'require.php' ) crashing Apache 1.3.28
    By akinder at technology-x dot com in forum PHP Development
    Replies: 0
    Last Post: October 8th, 09:01 PM
  4. #25782 [Opn->Fbk]: require( 'require.php' ) crashing Apache 1.3.28
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: October 8th, 12:56 AM
  5. #25782 [NEW]: require( 'require.php' ) crashing Apache 1.3.28
    By akinder at technology-x dot com in forum PHP Development
    Replies: 0
    Last Post: October 8th, 12:33 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139