'use' changed to 'require'

Discussion in 'Perl Misc' started by John, Jan 14, 2010.

  1. John

    John Guest

    Hi

    I've changed
    use Socket;
    to
    require Socket;

    in a subroutine since I use it infrequently

    I'm getting the error message

    Bareword "AF_INET" not allowed while "strict subs"

    What have I done?

    Regards
    John
     
    John, Jan 14, 2010
    #1
    1. Advertising

  2. "John" <> wrote:
    >I've changed
    >use Socket;
    >to
    >require Socket;
    >
    >in a subroutine since I use it infrequently
    >
    >I'm getting the error message
    >
    >Bareword "AF_INET" not allowed while "strict subs"
    >
    >What have I done?


    Isn't that obvious? You changed
    use Socket;
    to
    require Socket;
    ;-))

    Seriously, you are missing the import() part of use(), see
    perldoc -f use

    jue
     
    Jürgen Exner, Jan 14, 2010
    #2
    1. Advertising

  3. John

    John Guest

    "Jürgen Exner" <> wrote in message
    news:...
    > "John" <> wrote:
    >>I've changed
    >>use Socket;
    >>to
    >>require Socket;
    >>
    >>in a subroutine since I use it infrequently
    >>
    >>I'm getting the error message
    >>
    >>Bareword "AF_INET" not allowed while "strict subs"
    >>
    >>What have I done?

    >
    > Isn't that obvious? You changed
    > use Socket;
    > to
    > require Socket;
    > ;-))
    >
    > Seriously, you are missing the import() part of use(), see
    > perldoc -f use
    >
    > jue


    I've added Socket->import(); but same error - John
     
    John, Jan 14, 2010
    #3
  4. "John" <> wrote:
    >"Jürgen Exner" <> wrote in message
    >> "John" <> wrote:
    >>>I've changed
    >>>use Socket;
    >>>to
    >>>require Socket;
    >>>
    >>>in a subroutine since I use it infrequently
    >>>
    >>>I'm getting the error message
    >>>
    >>>Bareword "AF_INET" not allowed while "strict subs"
    >>>
    >>>What have I done?

    >>
    >> Isn't that obvious? You changed
    >> use Socket;
    >> to
    >> require Socket;
    >> ;-))
    >>
    >> Seriously, you are missing the import() part of use(), see
    >> perldoc -f use

    >
    >I've added Socket->import(); but same error - John


    Oh, yeah, of course, sorry. The "Bareword ..." message is a compile time
    error while the require/import would be done at run time, i.e. way
    later.

    Not sure what to do about it, I'm not familiar with Socket or what
    AF_INET is. I guess maybe you could use a fully qualified name.

    jue
     
    Jürgen Exner, Jan 14, 2010
    #4
  5. John

    Uri Guttman Guest

    >>>>> "JE" == Jürgen Exner <> writes:

    JE> "John" <> wrote:

    >> I've added Socket->import(); but same error - John


    JE> Oh, yeah, of course, sorry. The "Bareword ..." message is a compile time
    JE> error while the require/import would be done at run time, i.e. way
    JE> later.

    JE> Not sure what to do about it, I'm not familiar with Socket or what
    JE> AF_INET is. I guess maybe you could use a fully qualified name.

    AF_INET is a constant that shouldn't be needed in common socket
    code. he should be using IO::Socket instead which has a better API and
    less need of obscure constants.

    the OP should post the whole section of code with the socket stuff. and
    if he does need it, he can't do require and even import since the import
    has to be done at compile time for the constant to be declare properly
    and then parsed that way in his code. putting the import into a BEGIN
    would only help if the module were also loaded there but that becomes
    use again.

    another solution is to move all the code that involves the socket stuff
    to its own module, call use Socket in there, and load his module on
    demand.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Jan 14, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick LeBoutillier

    use/require handler?

    Patrick LeBoutillier, Jan 31, 2004, in forum: Perl
    Replies:
    4
    Views:
    495
    Gunnar Hjalmarsson
    Jan 31, 2004
  2. Replies:
    1
    Views:
    698
    Rosanne
    Oct 11, 2005
  3. ZyLo

    Proper use of 'require'

    ZyLo, Dec 30, 2005, in forum: Ruby
    Replies:
    2
    Views:
    102
    Hal Fulton
    Jan 1, 2006
  4. Replies:
    4
    Views:
    208
    Uri Guttman
    Jan 31, 2006
  5. mxbrunet
    Replies:
    1
    Views:
    221
Loading...

Share This Page