#!/usr/bin/perl -w use strict; my $logfile = "/var/log/whatever.log"; my $verbose = 0; parseArgs($#ARGV + 1, @ARGV); # # ... do stuff with the logfile ... # # subroutine parseArgs sub parseArgs { my ($argc, @argv) = @_; my $need_help = 0; # is mandatory to receive comand args? usage() if ( $argc == 0 ); for ( my $i=0; $i < $argc; $i++ ) { foreach ($argv[$i]) { if ( /^-logfile$|^-l$/ ) { if ( $argv[$i + 1] ) { #here you must do, if you want, some checks #before asing nothing ... $logfile = $argv[++$i]; } else { #complain! $needs_help = 1; } } elsif (/^-v$|^--verbose$/) { $verbose = 1; } elsif (/^-h$|^--help$) { $needs_help = 1; } else { print "Command argument ", ($argv[$i]), " is not valid\n"); $needs_help = 1; } } } usage() if ( $needs_help ); } sub usage { print <