Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > 'use' changed to 'require'

Reply
Thread Tools

'use' changed to 'require'

 
 
John
Guest
Posts: n/a
 
      01-14-2010
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


 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      01-14-2010
"John" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      01-14-2010

"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "John" <(E-Mail Removed)> 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



 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-14-2010
"John" <(E-Mail Removed)> wrote:
>"Jürgen Exner" <(E-Mail Removed)> wrote in message
>> "John" <(E-Mail Removed)> 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
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2010
>>>>> "JE" == Jürgen Exner <(E-Mail Removed)> writes:

JE> "John" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
changed state to up changed state to down FastEthernet LINEPROTO-5-UPDOWN surrealarmada@gmail.com Cisco 3 03-07-2007 06:06 PM
scroll position is changed when style is changed? mxbrunet Javascript 1 11-03-2006 03:40 AM
xmlDocument.Save "&#10;" getting changed changed to "&amp;#10" st@jpa.co.jp ASP .Net 1 10-11-2005 01:30 PM
Changed XP home edition to professional Vik Wireless Networking 0 07-30-2004 12:52 PM
Changed XP home edition to Professional and lost Wireless settings Vik Wireless Networking 2 07-29-2004 08:01 PM



Advertisments