Why am I getting an undefined subroutine error? 
Author Message
 Why am I getting an undefined subroutine error?

I have Perl installed on my Windows NT system and am trying to make use of
some of packages that are part of the distribution. I tried a very simple
script:

use Net::ping;
print "alive" if pingecho('localhost', 10);

but when I run this I get the error

    Undefined subroutine &main::pingecho called at - line 2

Can anyone explain what is causing this error?



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?
Peter:

Quote:
> use Net::ping;

> print "alive" if pingecho('localhost', 10);

> but when I run this I get the error

>     Undefined subroutine &main::pingecho called at - line 2

> Can anyone explain what is causing this error?

use Net::Ping;

--
// Lee Silver
// Information Concepts Inc.

Facilitating the automated conversion of Data into Information
since 1982



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?

Quote:

> I have Perl installed on my Windows NT system and am trying to make use of
> some of packages that are part of the distribution. I tried a very simple
> script:

> use Net::ping;
> print "alive" if pingecho('localhost', 10);

> but when I run this I get the error

>     Undefined subroutine &main::pingecho called at - line 2

> Can anyone explain what is causing this error?

Yes.  Even on win32 systems, Perl is case-sensitive.  The module
is named Net::Ping , not Net::ping .  Perl couldn't find the
module because of the case error.

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?

Quote:

> I have Perl installed on my Windows NT system and am trying to make use of
> some of packages that are part of the distribution. I tried a very simple
> script:

> use Net::ping;
> print "alive" if pingecho('localhost', 10);

> but when I run this I get the error

>     Undefined subroutine &main::pingecho called at - line 2

> Can anyone explain what is causing this error?

You either have a typo in your little snippet above, or you're lying
to us.

The use() statements get executed in compile time. The correct module
name in Net::Ping. Perl is case-sensitive, even on winblows.


would've never gotten the error, which happens at run time.

HTH,

--Ala



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?


Quote:

>> I have Perl installed on my Windows NT system and am trying to make use of
>> some of packages that are part of the distribution. I tried a very simple
>> script:

>> use Net::ping;
>> print "alive" if pingecho('localhost', 10);

>> but when I run this I get the error

>>     Undefined subroutine &main::pingecho called at - line 2

>> Can anyone explain what is causing this error?

>You either have a typo in your little snippet above, or you're lying
>to us.

Or you're using a case-insensitive filesystem; given that you're on
Windows NT, that's probably the case.

Quote:
>The use() statements get executed in compile time. The correct module
>name in Net::Ping. Perl is case-sensitive, even on winblows.

Perl is case-sensitive for package method lookup, but not filename
lookup.  But if, on Unix, I have a Net/ping.pm that says:
package Net::Ping;
sub pingecho { 'foo' }
1;

. . . I can happily say
use Net::ping;
and not know that anything is wrong.

Quote:
>Unless you have a module called Net::ping hidden somewhere in your

>would've never gotten the error, which happens at run time.

As far as perl can tell (at least by attempting to open() it, which is
what it does on Unix and, I assume, on Windows too), it *is* called
Net/ping.pm.

This guy is the second one today to report this problem, so I suspect
he's not lying.
--

Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?

Quote:




> >> I have Perl installed on my Windows NT system and am trying to make use of
> >> some of packages that are part of the distribution. I tried a very simple
> >> script:

> >> use Net::ping;
> >> print "alive" if pingecho('localhost', 10);

> >> but when I run this I get the error

> >>     Undefined subroutine &main::pingecho called at - line 2

> >> Can anyone explain what is causing this error?

> >You either have a typo in your little snippet above, or you're lying
> >to us.

> Or you're using a case-insensitive filesystem; given that you're on
> Windows NT, that's probably the case.

Of course it is. The original poster clearly indicates that he's on a
WinNT system.

Quote:
> >The use() statements get executed in compile time. The correct module
> >name in Net::Ping. Perl is case-sensitive, even on winblows.

> Perl is case-sensitive for package method lookup, but not filename
> lookup.  But if, on Unix, I have a Net/ping.pm that says:
> package Net::Ping;
> sub pingecho { 'foo' }
> 1;

> . . . I can happily say
> use Net::ping;
> and not know that anything is wrong.

Hmm. I don't get it. Maybe I am confused, but here's what actually
happens:

% cd myNet
% cat Ping.pm
package myNet::Ping;
1;
% cd ..
% perl -MmyNet::Ping -e 1
% perl -MmyNet::ping -e 1

/opt/perl-5.005_03/lib/5.00503/sun4-solaris
/opt/perl-5.005_03/lib/5.00503
/opt/perl-5.005_03/lib/site_perl/5.005/sun4-solaris
/opt/perl-5.005_03/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.

Now, let's try to rename Ping.pm to ping.pm and see:

% cd myNet
% mv Ping.pm ping.pm
% cd ..
% perl -MmyNet::Ping -e 1

/opt/perl-5.005_03/lib/5.00503/sun4-solaris
/opt/perl-5.005_03/lib/5.00503
/opt/perl-5.005_03/lib/site_perl/5.005/sun4-solaris
/opt/perl-5.005_03/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.
% perl -MmyNet::ping -e 1
%

So, if I understand correctly, it does matter whether the file is
Net::Ping or Net::ping (on a real file-system at least. I didn't test
on winblows). But it doesn't matter whether the package
declaration within the file is Net::Ping or Net::ping.

I don't like that. Does this mean that my FOO::Bar::* variables will
clash with my FOO::bar::* variables?

Quote:
> >Unless you have a module called Net::ping hidden somewhere in your

> >would've never gotten the error, which happens at run time.

> As far as perl can tell (at least by attempting to open() it, which is
> what it does on Unix and, I assume, on Windows too), it *is* called
> Net/ping.pm.

> This guy is the second one today to report this problem, so I suspect
> he's not lying.

I hope it came across everyone's mind that I was joking when I said
that. Accusing him of lying wasn't my intention, and I simply thought
that he didn't cut and paste his code.

--Ala



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?


Quote:
>Hmm. I don't get it. Maybe I am confused, but here's what actually
>happens:

Method lookup is case-sensitive in Perl, just like always.  But
filename lookup depends on the OS.  So use Net::ping will find the
right file, but it won't find the import method.

Perl will happily do whatever is in the file, whether it is in the
package specified by the filename or not.  This is sometimes thought of
as a good thing, as it allows you to put many private classes in a
file.

Quote:
>So, if I understand correctly, it does matter whether the file is
>Net::Ping or Net::ping (on a real file-system at least. I didn't test
>on winblows). But it doesn't matter whether the package
>declaration within the file is Net::Ping or Net::ping.

No.  It doesn't matter whether the package declaration within the file
is Net::Ping or Sousa::Fluegelhorn.  Until you try to call routines or
methods from the package, at which point it doesn't matter what the
filename was.

So what's happening is that he has the wrong package name, but perl
finds the file anyway because the fs is case-insensitive, but fails to
import the desired routines because there is no Net::ping package in
the file he included, just a Net::Ping package.

Quote:
>I hope it came across everyone's mind that I was joking when I said
>that. Accusing him of lying wasn't my intention, and I simply thought
>that he didn't cut and paste his code.

I hope so too.  :)
--

Tue Nov 02 1999
6 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?

Quote:

>Even on win32 systems, Perl is case-sensitive.  The module
>is named Net::Ping , not Net::ping .  Perl couldn't find the
>module because of the case error.

Well, it COULD. It found the file. It didn't import anything, because of
the case error, and Net::ping::import wasn't found. I would think.

--
        Bart.



Wed, 18 Jun 1902 08:00:00 GMT  
 Why am I getting an undefined subroutine error?
[big snip]

Quote:
> As far as perl can tell (at least by attempting to open() it, which is
> what it does on Unix and, I assume, on Windows too), it *is* called
> Net/ping.pm.

> This guy is the second one today to report this problem, so I suspect
> he's not lying.

No, he just posted his problem twice.  Same guy.

David
--

Senior computing specialist
mathematical statistician



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Why am I getting an error with @_ ?

2. Why am I getting this regexp error?

3. Getting 500 Undefined subroutine &HTML::Entities::decode_entities called

4. why is Vars an undefined subroutine?

5. Help! Inexplicable error: undefined subroutine

6. AdminMisc error: goto undefined subroutine

7. Help: undefined subroutine error using Win32::ODBC

8. error: undefined subroutine &Date::Parse::strptime

9. Error - Undefined subroutine &Win32::Process::Create

10. undefined subroutine error using InitiateSystemShutdown

11. Undefined subroutine error

12. Error:Undefined subroutine &main ?

 

 
Powered by phpBB® Forum Software