sub process_command_line_args { #set default values for dynamic config settings my ($layout,$wait_for_child,$wait_for_exec,$prompt,$configf,$quiet,$outf,$debug,$batchsize,$proto,$tacacs,$verbose,$header,@maildst) = (0,120,3,1,"$name.cfg",1,"$name.csv",0,0,"none",0,0); GetOptions ( ...) ... my @args = ($layout,$wait_for_child,$wait_for_exec,$name,$prompt,$configf,$quiet,$outf,$debug,$batchsize,$proto,$tacacs,$verbose,$header,$mailref,$path); return \@args; } #### sub Main { my %CONFIG; initialize_config_hash(\%CONFIG); get_command_line_args(\%CONFIG); validate_command_line_args(\%CONFIG); get_username_and_password_from_stdin(\%CONFIG) if $CONFIG{prompt}; ... } sub initialize_config_hash { my $CONFIG = shift; %$CONFIG = ( quiet => 0 , cfg => "$name.cfg" , verbose => 0 , outcsv => "$name.csv" , debug => 0 , proto => "none" , prompt => 1 , header => undef , layout => 0 , maildst => [] , wait_for_child => 120 , mail_to => "" , wait_for_exec => 0 , mail_from => "NMS-script@me.net" , batchsize => 0 , mail_sub => "" , tacacs => 0 , mail_cc => "" , tacuser => "user" , mail_data => "" , tacpass => "pass" , ); } sub get_command_line_args { my $CONFIG = shift; GetOptions ( 'layout|l' => \$CONFIG->{layout}, 'file-based-auth|f' => sub { \$CONFIG->{prompt} = 0; }, 'prompt-based-auth|p' => sub { \$CONFIG->{prompt} = 1; }, ... ) ... } #### $WARN = 0; #supress flow control warning in following block due to exiting anon sub LOOPCTRL: while ($lb < 10){ $exp->expect(... [ ..., sub {... $lb++; next LOOPCTRL; }], ... ); $exp->expect(... [ ..., sub {... last LOOPCTRL; }] ); } $WARN = 1; # reset to default #### while (...) { next if $exp->expect(... ... ); last if $exp->expect(... ... ); } #### use strict; use warnings; # warnings coming from here will be printed { no warnings; # warnings coming from here will NOT be printed } # warnings coming from here will be printed #### # Don't warn about exiting subs via loop control: no warnings 'exiting'; # Don't warn about using undef in numeric or string operations: no warnings 'uninitialized'; #### { local $SIG{__WARN__} = sub {}; # call the noisy module function here } # warnings coming from here will not be affected #### \%{ $CONFIG } \%$CONFIG #### my $range = '1000000'; my $rand = int(rand($range)); ##generate random temp-db filename to allow for simultanous script execution ... tempdb => "$path/$rand.db", #### my $foo = $_[0]; #### my $foo = shift; #### my ($foo) = @_;