Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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:


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?

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?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-11-21 11:36 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (239 votes). Check out past polls.