http://www.perlmonks.org?node_id=1055240


in reply to RFC: beginner level script improvement

sub sendmail { my ($REPORT,$CONFIG,$RESULT) = @_; my $T = gettime(); my $MAIL_TO = $CONFIG{MAIL_TO}[0]; delete $CONFIG{MAIL_TO}[0]; my @MAIL_CC = $CONFIG{MAIL_TO};

You pass in three arguments ($REPORT, $CONFIG and $RESULT) but you never actually use these references inside this subroutine.

delete $CONFIG{MAIL_TO}[0] changes the current value of $CONFIG{MAIL_TO}[0] to undef and returns the previous value, it does not change the size of the array.    What you probably really want to do is:

my $MAIL_TO = shift @{ $CONFIG{ MAIL_TO } };

You assign the scalar value $CONFIG{MAIL_TO} to an array but you should just assign it to a scalar variable:

my $MAIL_CC = $CONFIG{ MAIL_TO };


if ($RESULT == 1){ ... }else{ $CONFIG{MAIL_DATA} .= "ERROR: TACACS SERVICE VERIFICATION FAIL +ED!\nReason:"; if ($RESULT == 1){ $CONFIG{MAIL_DATA} .= "HUBSITE: $CONFIG{HUB +SITE} is unreachable\n";} if ($RESULT == 2){ $CONFIG{MAIL_DATA} .= "Provided Username/pa +ssword combination failed Auth +entication\n";} if ($RESULT == 2){ $CONFIG{MAIL_DATA} .= "Provided Username/pa +ssword combination passed Auth +entication, but tacacs profile doesn't allow privileged mode\n";}

The else block of if ($RESULT == 1){ means that $RESULT is NOT equal to 1 but you still test for that.

Why do you have two tests for $RESULT == 2?