1) Remember just beginning to write Perl, for a function, always take the current data types can be used to solve the problem, do not want to think there is no better, can be used to solve the problem is good, which led to the late, to add functionality inside the function, the function to add a lot of parameters, a function has 7, 8 parameters, And these parameters are all related,
sub is_healthy{
my ($name, $sex, $age, $height, $weight) = @_;
}
like the above to judge whether a person is healthy function, passed these parameters, these parameters are not too much, but, to the later, once you want to add functionality, such as to do some operations according to a person's address, it may be necessary to add another parameter, OK, the parameters of one more, but, The demand may be increasing, plus one more parameter .... The last parameter will be a lot, when calling the function, always see the long tail. That's what I wrote. Finally, after the senior remind, only to find that they really did not think about this problem, why not hash it, how simple and convenient, like this,
My $human = {};
$human->{name} = "1y";
when passing the parameters, just pass one,
Is_healthy ($human);
If you want to add parameters, just add the key value in the hash is good, so in the call function, do not have to do anything to change, easy, but for some irrelevant parameters, have to think about.
2) Perl-E for the interpretation of existence, see the code written by others, use-e to determine whether a directory or file exists,
sub is_healthy{
my ($name, $sex, $age, $height, $weight) = @_;
}
This can determine whether the directory exists, assuming that after the directory exists, the next operation is for the directory operation, but if you accidentally passed a file, and the file was originally for the directory operation, then the future is full of unknown, to be scolded ...
To determine the directory can be used with-D, in this case with-e risk, may be the wrong parameters to the code.
Perl Learning Notes (2)