You see, I want to rewrite my current subroutines and allow for default values, or null values. I was trying the code above, but can't figure out how to get it to work. You see, the command changes based upon input.

Sometimes the command will be:
/usr/bin/passwd -n 1 -w 5 -x 30

Sometimes the command will be:
/usr/bin/passwd -n 1 -w 5 -x 60

and sometimes the command will be:
/usr/bin/passwd -x -1

I would like to set default values for n (1), w(5) and x(60), but also allow them to be null, like in the case of the last command... Just trying to figure out the best way to do this.

Current Code:
sub SUNPwdAging { my $loginid = shift; my $pwminlife = shift; my $pwmaxlife = shift; my $pwdwarn = shift; my $command; my $match_num; my $error; my $match; my $before; my $after; my $passwd = "/usr/bin/passwd"; my $options = "-n $pwminlife -x $pwmaxlife -w $pwdwarn"; # Define full command $command = "$passwd $options $loginid"; # Set the Aging $Login::rsh->clear_accum(); print $Login::rsh "$command\; echo \$?\r"; ($match_num,$error,$match,$before,$after)= $Login::rsh->expect($Login::TIME_OUT, '-re', '(?s).*\r\n[1-7]\r?$' ,'-re', '(?s).*\r\n0\r?$' ); if ($match_num == 1) { $result = "FAILED: ".$match.": ".$after; } elsif ($match_num == 2) { $result = "SUCCESSFUL"; } elsif (defined($error)) { $result = "FAILED: ".$error; } else { $result = "FAILED: Unknown error occurred."; } return $result; }
Would like it to be something more like this...
sub SunPwdAging { my %defaults = (qw(n 1 w 5 x 60)) my %args = (%defaults, @_); my $result; ....
But then, how do I setup the command to even use what's passed to the subroutine?

In reply to Re^2: Default Values in Subroutines by walkingthecow
in thread Default Values in Subroutines by walkingthecow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.