'use' changed to 'require'

J

John

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
 
J

Jürgen Exner

John said:
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

John

Jürgen Exner said:
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
 
J

Jürgen Exner

John said:
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
 
U

Uri Guttman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top