my %params=( host => (TYPE=>"s", REQUIRED=>1, VALUE=>undef, VALIDATE=>sub { # Tis could be a subref to an external, if it gets too big my $host=shift; print "\nChecking if $host is alive.. \n"; $ping = Net::Ping->new(); if ($ping->ping($host)){ print "$host is alive\n\n"; }else { print "$host is unreachable\n\n"; exit; } $ping->close(); }, ), # End of host engine => (TYPE=>"s", REQUIRED=>1, VALUE=>undef,), user => (TYPE=>"s", REQUIRED=>1, VALUE=>undef), password => (TYPE=>"s", REQUIRED=>1, VALUE=>undef), ); #### GetOptions( map { "$_=$params{$_}{TYPE}" => \$params{$_}{VALUE} } keys %params ); for (keys %params){ showUsage("Missing required parameter $_") if $params{$_}{REQUIRED} && ! $params{$_}{VALUE}; $params{$_}{VALIDATE}->($params{$_}{VALUE}) if $params{$_}{VALIDATE}; }