Perform consistent command line parsing : Getopt « System Functions « Perl






Perform consistent command line parsing

      

    #!/usr/local/bin/perl -w
    use 'Getopt::Std'

    getopt('abcd:ef:');
    print "Switch a is on\n" if $opt_a;
    print "Switch b is on \n" if $opt_b;
    print "Switch c is on \n" if $opt_c;
    print "Debug switch set to $opt_d\n" if $opt_d > 5;
    print "Switch e is on\n" if $opt_e;
    if ($opt_f) {
      print "Cannot locate file $opt_f\n" unless -e $opt_f;
    }

    for $I (1..5) {
      print "Value of I is $I\n" if $opt_d;
    }

    print "No (more) switches specified\n";

   
    
    
    
    
    
  








Related examples in the same category

1.Simple options
2.GetOptions("file=s" => \$file);
3.Generate random passwords?
4.Extract command-line switches with Getopt::Std
5.Process complex command lines
6.Read from a file
7.To turn a feature on or off. Use the exclamation point(!)
8.Using Getopt to deal with command line options
9.getopt('pMN');
10.If the value is optional, use a colon
11.For a text string value, use :s for an optional value or =s for a required value:
12.Check if a file exists
13.A double dash (--) by itself signals the end of the command-line switches.