[CMI.PM] Getopt::Long UPPERCASING EVERYTHING (fwd)

Mitch Kutzko mitch at ncsa.uiuc.edu
Thu Oct 16 14:27:42 CDT 2003


> > ----- Forwarded message from mitch at ncsa.uiuc.edu -----
> >
> > Date: Wed, 08 Oct 2003 10:54:48 -0500
> > To: CU Perlmongers <champaign-urbana at mail.pm.org>
> > From: Mitch Kutzko <mitch at ncsa.uiuc.edu>
> > Subject: Getopt::Long UPPERCASING EVERYTHING
> >
> > Hi, folks -- Looking for a little help with module Getopt::Long.
> >
> > I have it working fine in a script to processing command line/config
> > file options, but if I supply text to it via the config file option,
> > it uppercases the entire string.
> >
> > Is there a way to tell it to just hand me the string as it was
> > entered? I'm already using
> >
> > Getopt::Long::Configure ("bundling");   # Allow long and short args both
> >
> > To handle both long and short arguments, but couldn't find an option
> > that handles case.
> >
> > Thanks!
> >
> > Mitch
> 
> I don't really understand what you're asking/trying to do (some
> examples and/or some code would be helpful), but does the option
> "ignore_case" help?

I have a config file that I'm ready.

If it contains:

	CONTACTNAME             = Mitch Kutzko

I get:
	MITCH KUTZKO

If I specify the same option via command line and give:

	perl woof.pl -a Mitch Kutzko

I get:

	Mitch Kutzko



An excerpted code sample follows:
#-------------------------

sub get_opts() {
  Getopt::Long::Configure ("bundling");   # Allow long and short args both
        # Using a, b, c, d, f, g, h, i, l, m, n, o, p s, t, u, v, w
  GetOptions(   'group|g=s'     => \$GROUP,
        'port|p=s'              => \$PORT,
        'ttl|l=s'               => \$TTL,
        'configfile|f=s'        => \$CONFIGFILE,
        'centralservername|c=s' => \$CENTRALSERVERNAME,
        'serverptcport|t=s'     => \$SERVERTCPPORT,
        'becentralserver|b'     => \$becentralserver,
        'noshutdownmsg|u'       => \$noshutdownmsg,
        'nohtml|n'              => \$nohtml,
        'stdout|s'              => \$stdout,
        'stopme|o'              => \$stopme,
        'SHOWMOTD|m'            => \$showmotd,
        'MOTD|d=s'              => \$MOTD,
        'CONTACTNAME|a=s'       => \$CONTACTNAME,
        'CONTACTINFO|i=s'       => \$CONTACTINFO,
        'help|h|?'              => \$needs_help ) || die ("Unknown option
(see above) included in the command line, triggered" );

#[ much snippage ]


  open(CONFIGFILE, $CONFIGFILE) || die ("CONFIGFILE open failed -
\"$CONFIGFILE\"" );

  while (<CONFIGFILE>) {
    chomp;                  # no newline
    s/#.*//;                # no comments
    s/^\s+//;               # no leading white
    s/\s+$//;               # no trailing white
    next unless length;     # anything left?
    my ($var, $value) = split(/\s*=\s*/, uc $_, 2);
    $opts{$var} = $value;
  }
  close(CONFIGFILE) || die ("Couldn't close CONFIGFILE" );

  foreach my $var (sort keys %opts) {

        if ($var eq "GROUP") {
                $GROUP = $opts{$var};
        } elsif ($var eq "PORT") {
                $PORT = $opts{$var};
        } elsif ($var eq "TTL") {
                $TTL = $opts{$var};
        } elsif ($var eq "NOSHUTDOWNMSG") {
                $noshutdownmsg = $opts{$var};
        } elsif ($var eq "NOHTML") {
                $nohtml = $opts{$var};
        } elsif ($var eq "SHOWMOTD") {
                $showmotd = $opts{$var};
        } elsif ($var eq "MOTD") {
                $MOTD = $opts{$var};
        } elsif ($var eq "STDOUT") {
                $stdout = $opts{$var};
        } elsif ($var eq "STOPME") {
                $stopme = $opts{$var};
        } elsif ($var eq "CONTACTNAME") {
                $CONTACTNAME = $opts{$var};
        } elsif ($var eq "CONTACTINFO") {
                $CONTACTINFO = $opts{$var};
        } elsif ($var eq "CENTRALSERVERNAME") {
                $CENTRALSERVERNAME = lc($opts{$var});
        } elsif ($var eq "SERVERTCPPORT") {
                $SERVERTCPPORT = $opts{$var};
        } elsif ($var eq "BECENTRALSERVER") {
                $becentralserver = $opts{$var};
        } else {
                die ("Unknown option in config file \"$CONFIGFILE\" -
\"$var\"");
        }
  }

#[ much snippage ]

}


#-----------------------------
# Inside main here....

  get_opts();     # Find out what command line options they gave us, or
read from config file if they didn't.

#[ much snippage ]


  print "This Beacon is reporting as \"$thisbeacon\", OS is $^O. Current
PID is $$.\n";
  if ($CONTACTNAME eq "") {
        print "No Contact Name specified for this Beacon. PLEASE EDIT
beacon.conf!\n";
  } else {
        print "Contact Name for this Beacon: \"$CONTACTNAME\".\n";
  }
  if ($CONTACTINFO eq "") {
        print "No Contact Information specified for this Beacon. PLEASE
EDIT beacon.conf!\n";
  } else {
        print "Contact Information for this Beacon: \"$CONTACTINFO\".\n";
  }
  printf "Perl version is %vd,  ", $^V;
  print "Beacon started at: $starttime";
#----------------------------


Any help appreciated.....

Thanks!

Mitch
--
Mitch Kutzko | mitch at dast.nlanr.net | mitch at ncsa.uiuc.edu | 217-333-1199
http://hobbes.ncsa.uiuc.edu/



More information about the Champaign-Urbana mailing list