Hi all,

Playing around with Getopt::Std as am trying to convert a UNIX Korn Shell
Script to a Perl script.

Is it possible to check for what are the values for opterr, optarg, optind?
How? :(-

I've been Googling for quite sometime now and can't find an example of Perl
scripts that checks for opterr, optarg, optind and then do something with
them. Also, am trying to set opterr=0 so I don't get errors for when an
unknown option is provided. Is this possible or not possible?


/+  ------------------- Script ------------------------------ +/

#!/bin/perl -w

use strict;
use Getopt::Std;

##################
# Some Variables #
##################

# -----------------------------------------------------------------
# How to check for the values of - opterr, optarg, optind - ???
# -----------------------------------------------------------------

my $opterr=0;                   # Supposed to turn off messages - ???
my $processid=$$;
my $header="";
my $size="";
my $filesystem="";
my %options=();

getopts( "f:kgm" , \%options );

########
# MAIN #
########

if ( $options{'g'} ) {
   $size="GB";
   $header="Filesystem GBytes Used Avail Capacity Mount"
} elsif ( $options{'m'} ) {
   $size="MB";
   $header="Filesystem MBytes Used Avail Capacity Mount"
} elsif ( $options{'k'} ) {
   $size="KB";
   $header="Filesystem KBytes Used Avail Capacity Mount"
} else {
   $size="GB";
   $header="Filesystem GBytes Used Avail Capacity Mount"
}

if ( $options{'f'} ) {
   $filesystem=$options{'f'};
}

print "size = $size \n";
print "header = $header \n";
print "filesystem = $filesystem \n";
###########
# THE END #
###########
 /+  ------------------- Sample RUN ------------------------------ +/

server01$: ./opt-01.pl
size = GB
header = Filesystem GBytes Used Avail Capacity Mount
filesystem =
server01$: ./opt-01.pl -m
size = MB
header = Filesystem MBytes Used Avail Capacity Mount
filesystem =
*server01$: ./opt-01.pl -x
Unknown option: x          <-- how to mask / hide this error/warning?
*size = GB
header = Filesystem GBytes Used Avail Capacity Mount
filesystem =
server01$: ./opt-01.pl -m -f /home/users
size = MB
header = Filesystem MBytes Used Avail Capacity Mount
filesystem = /home/users
Any help/feedback will be much appreciated. Thanks in advance.

Reply via email to