Mystery message: Undefined subroutine &OS2::Bootdrive

Discussion in 'Perl Misc' started by Shmuel (Seymour J.) Metz, Sep 22, 2004.

  1. 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
     
    Shmuel (Seymour J.) Metz, Sep 22, 2004
    #1
    1. Advertising

  2. 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";
    >
    >
     
    Darin McBride, Sep 22, 2004
    #2
    1. Advertising

  3. Shmuel (Seymour J.) Metz

    Polleke Guest

    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
     
    Polleke, Sep 23, 2004
    #3
  4. In <Vgm4d.75406$%S.49494@pd7tw2no>, on 09/22/2004
    at 09:37 PM, Darin McBride <>
    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
     
    Shmuel (Seymour J.) Metz, Sep 23, 2004
    #4
    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. jeff
    Replies:
    0
    Views:
    368
  2. Replies:
    9
    Views:
    289
    Keith Thompson
    Jul 19, 2006
  3. Replies:
    2
    Views:
    322
    Richard Herring
    Jul 19, 2006
  4. kerravon
    Replies:
    0
    Views:
    470
    kerravon
    Aug 23, 2009
  5. king
    Replies:
    5
    Views:
    210
Loading...

Share This Page