I have a subroutine in a perl module and I would like to know best way to have default values, or values that can be passed but have no defaults. For example, sometimes you want to set BOOTPW, but not always, and there really is no default value -- either it is set, or it is not. So, instead of having a default value, how would I set it up to accept it as a parameter without a default value? Also, there is no default value for ID, but not sure how to do that either. However, for some flags there IS a default value, such as exptm which has a default value of -1, but can be changed with parameters. Anyway, here's the code that I have thus far:
sub setAgeHP { my %defaults = (qw(mintm -1 expwarn -1 lftm -1 acctexp -1 exptm -1 + llog -1 bootpw NO umaxlntr -1 id null)) my %args = (%defaults, @_); my $return; if ($args{'pwdage'} == 30) { $hpmod="/usr/lbin/modprpw -k -m "; } else { $hpmod="/usr/lbin/modprpw -m "; } print $rsh "$hpmod $args{id};echo \$?\r"; ($match_num,$error,$match,$before,$after)= $rsh->expect($TIME_OUT, '-re', '^[1-9][0-9][0-9]\r?$' ,'-re', '^[1-9][0-9]*\r?$' ,'-re', '(?s).*\r\n0\r?$'); if ($match_num == 3) { $result = "SUCCESSFUL"; } else { $result = "FAILED with exit code $match"; } return $result; }
In reply to Default Values in Subroutines by walkingthecow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |