Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Mystery message: Undefined subroutine &OS2::Bootdrive

Reply
Thread Tools

Mystery message: Undefined subroutine &OS2::Bootdrive

 
 
Shmuel (Seymour J.) Metz
Guest
Posts: n/a
 
      09-22-2004
I've been modifying a Perl Program to support OS/2, and I've run into
a bizare anomaly with the ternary operator. I was getting an error
message on the statement

my $etc = $ENV{ETC} or ($^O eq 'os2') ? OS2::Bootdrive() :
'/etc';

So I decided to try testing it a bit at a time. Each of the following
produces the expected output:

print '$ENV{ETC}=',$ENV{ETC},"\n";
print "OS=$^O\n";
print '$^O eq os2=',($^O eq 'os2'),"\n";
print 'BootDrive=',OS2::BootDrive(),"\n";
print "($^O eq 'os2') ? OS2::Bootdrive() : '/etc'=";
print $^O eq 'os2' ? 'true' : 'false',"\n";

[H:\]bwwhois 200.204.145.122
$ENV{ETC}=G:\MPTN\ETC
OS=os2
$^O eq os2=1
BootDrive=g
(os2 eq 'os2') ? OS2::Bootdrive() : '/etc'=true

However,

print $^O eq 'os2' ? OS2::Bootdrive() : '/etc',"\n";

gives me

Undefined subroutine &OS2::Bootdrive called at H:\UTILITY/BWwhois.cmd
line 61.

Note that the spelling is identical to the one that worked, so I
assume that the problem has something to do with the context of a
ternary operator. Any assistance will be appreciated.

The relevant code in context is:

require 5.006_00; # must use a modern perl
use strict;
use IO::File;
use IO::Socket;
use Getopt::Long;
use Fcntl ':flock';

my $VERSION = "3.4";

# Changes in support of OS/2
print '$ENV{ETC}=',$ENV{ETC},"\n";
print "OS=$^O\n";
print '$^O eq os2=',($^O eq 'os2'),"\n";
print 'BootDrive=',OS2::BootDrive(),"\n";
print "($^O eq 'os2') ? OS2::Bootdrive() : '/etc'=";
print $^O eq 'os2' ? 'true' : 'false',"\n";
print $^O eq 'os2' ? OS2::Bootdrive() : '/etc',"\n";
exit;
my $etc = $ENV{ETC};
#my $etc = $ENV{ETC} or ($^O eq 'os2') ? OS2::Bootdrive() : '/etc';
my $whois = File::Spec->catdir($etc,'whois');
# print '$etc=',$etc,"\n";
# print '$whois=',$whois,"\n";


--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Darin McBride
Guest
Posts: n/a
 
      09-22-2004
Shmuel (Seymour J.) Metz wrote:

> I've been modifying a Perl Program to support OS/2, and I've run into
> a bizare anomaly with the ternary operator. I was getting an error
> message on the statement
>
> my $etc = $ENV{ETC} or ($^O eq 'os2') ? OS2::Bootdrive() :
> '/etc';
>
> So I decided to try testing it a bit at a time. Each of the following
> produces the expected output:
>
> print '$ENV{ETC}=',$ENV{ETC},"\n";
> print "OS=$^O\n";
> print '$^O eq os2=',($^O eq 'os2'),"\n";
> print 'BootDrive=',OS2::BootDrive(),"\n";
> print "($^O eq 'os2') ? OS2::Bootdrive() : '/etc'=";
> print $^O eq 'os2' ? 'true' : 'false',"\n";
>
> [H:\]bwwhois 200.204.145.122
> $ENV{ETC}=G:\MPTN\ETC
> OS=os2
> $^O eq os2=1
> BootDrive=g
> (os2 eq 'os2') ? OS2::Bootdrive() : '/etc'=true
>
> However,
>
> print $^O eq 'os2' ? OS2::Bootdrive() : '/etc',"\n";
>
> gives me
>
> Undefined subroutine &OS2::Bootdrive called at H:\UTILITY/BWwhois.cmd
> line 61.
>
> Note that the spelling is identical to the one that worked, so I
> assume that the problem has something to do with the context of a
> ternary operator. Any assistance will be appreciated.


I would actually assume it's the comma ... try putting some extra
parens in there to keep your meaning clear:

print ($^O eq 'os2' ? OS2::Bootdrive() : '/etc'),"\n";

> The relevant code in context is:
>
> require 5.006_00; # must use a modern perl
> use strict;
> use IO::File;
> use IO::Socket;
> use Getopt::Long;
> use Fcntl ':flock';
>
> my $VERSION = "3.4";
>
> # Changes in support of OS/2
> print '$ENV{ETC}=',$ENV{ETC},"\n";
> print "OS=$^O\n";
> print '$^O eq os2=',($^O eq 'os2'),"\n";
> print 'BootDrive=',OS2::BootDrive(),"\n";
> print "($^O eq 'os2') ? OS2::Bootdrive() : '/etc'=";
> print $^O eq 'os2' ? 'true' : 'false',"\n";
> print $^O eq 'os2' ? OS2::Bootdrive() : '/etc',"\n";
> exit;
> my $etc = $ENV{ETC};
> #my $etc = $ENV{ETC} or ($^O eq 'os2') ? OS2::Bootdrive() : '/etc';
> my $whois = File::Spec->catdir($etc,'whois');
> # print '$etc=',$etc,"\n";
> # print '$whois=',$whois,"\n";
>
>

 
Reply With Quote
 
 
 
 
Polleke
Guest
Posts: n/a
 
      09-23-2004
on Wednesday 22 September 2004 21:12, Shmuel (Seymour J.) Metz wrote:

[snip]

> print 'BootDrive=',OS2::BootDrive(),"\n";

^
> print "($^O eq 'os2') ? OS2::Bootdrive() : '/etc'=";

^
[snip]

> print $^O eq 'os2' ? OS2::Bootdrive() : '/etc',"\n";
>
> gives me
>
> Undefined subroutine &OS2::Bootdrive called at H:\UTILITY/BWwhois.cmd
> line 61.
>
> Note that the spelling is identical to the one that worked,


No it isn't; BootDrive() works, but Bootdrive() doesn't exist. Function
names are always case sensitive!

Paul

 
Reply With Quote
 
Shmuel (Seymour J.) Metz
Guest
Posts: n/a
 
      09-23-2004
In <Vgm4d.75406$%S.49494@pd7tw2no>, on 09/22/2004
at 09:37 PM, Darin McBride <(E-Mail Removed)>
said:

>I would actually assume it's the comma ...


Thanks, although that turned out to not be the problem. My Mark II
eyeball failed to note the difference in case between Bootdrive and
BootDrive. I should have looked for something simple before looking
for a subtle explanation

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (E-Mail Removed)

 
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
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Undefined subroutine CGI::Vars Mark Perl 0 07-26-2004 02:13 PM
intermittent "Undefined subroutine" with mod_perl Moulin Kluge Perl Misc 2 01-27-2004 10:22 PM
testing for 'undefined subroutine' Torsten Mangner Perl Misc 3 11-05-2003 02:23 AM
"Undefined subroutine" error (but it's defined, I think?) valerian2@hotpop.com Perl Misc 4 08-12-2003 10:26 PM



Advertisments