Mega Code Archive

 
Categories / Perl / System Functions
 

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";