in reply to Unexpected results returned from a hash

Your checkparms are ALWAYS running 5 times (for the 5 commands you have listed).

You have included the RESULTS of &checkparms in your %cmd hash... what I think you want is the ref (\&checkparms), which would change how you call it.
  • Comment on Re: Unexpected results returned from a hash

Replies are listed 'Best First'.
Re^2: Unexpected results returned from a hash
by tcf03 (Deacon) on Jun 21, 2005 at 19:22 UTC
    Thanks, that was the problem. I changed %cmd to look like this
    my %cmd=( "-p" => { "COMMAND" => { "linux" => "/usr/local/bin/setp +ass.expect $USERNAME $NEWPASS", "aix" => "" }, "ACTION" => "Password Changed", "CHECKMODES" => \&checkparms($MODE), "ERRORS" => { "$OS:256" => "$USERNAME Does +not exist" } }, "-d" => { "COMMAND" => { "linux" => "/usr/sbin/userdel - +r $USERNAME", "aix" => "" }, "ACTION" => "Deleted", "CHECKMODES" => \&checkparms, "ERRORS" => { "$OS:1536" => "$USERNAME Does n +ot exist" } }, "-a" => { "COMMAND" => { "linux" => "/usr/sbin/useradd $ +USERNAME && /usr/local/bin/setp +ass.expect $USERNAME $NEWPASS", "aix" => "" }, "ACTION" => "Added", "CHECKMODES" => \&checkparms, "ERRORS" => { "$OS:2304" => "$USERNAME exists +" } }, "-ha" => { "COMMAND" => { "linux" => "/usr/bin/htpasswd - +bd $APACHECONF $USERNAME $NEWPASS", "aix" => "" }, "ACTION" => "Added", "CHECKMODES" => \&checkparms }, "-hd" => { "COMMAND" => { "linux" => "/usr/bin/htpasswd - +D $APACHECONF $USERNAME", "aix" => "" }, "ACTION" => "Deleted", "CHECKMODES" => \&checkparms } );


    and the checkparms sub to look like this

    ############## sub checkparms ############## { push (@THINGS, "Username") if ( $USERNAME eq "UNDEFINED" ); push (@THINGS, "Password") if ( $NEWPASS eq "UNDEFINED" and $MODE eq "-a" or $MODE eq "-p" or $MODE eq "-ha"); push (@THINGS, "httpd.conf") if ( $MODE eq "-ha" or $MODE eq "-hd" and $APACHECONF eq "UNDEFINED" ); my $return_val = ( scalar(@THINGS) == 0 ) ? "0" : "1"; return $return_val; }


    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson