Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: RFC: beginner level script improvement

by jwkrahn (Monsignor)
on Sep 23, 2013 at 07:10 UTC ( #1055240=note: print w/ replies, xml ) Need Help??


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?


Comment on Re: RFC: beginner level script improvement
Select or Download Code
Replies are listed 'Best First'.
Re^2: RFC: beginner level script improvement
by georgecarlin (Acolyte) on Sep 23, 2013 at 14:29 UTC
    Thank you very much for pointing out these errors. I also didn't realize that my $var outside of Blocks was a file-wide declaration, I assumed its scope was limited to "Non-Blocks". Now it makes so much more sense =) Thank you for pointing that out! I'm still in the process of rewriting the improved version so this helps me a lot.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-08-01 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls