in reply to Omitted subroutine arguments
The traditional idiom is to have optional parameters at the end of the list. If there's only one optional arg, then either is is present or it isn't, which works out fine. The variable inside the subroutine will be undef, which you can detect and replace with an empty string, if necessary.
But if you're going to have several optional parameters, then you are forced to have undef arguments in the subroutine call, which is ugly. Worse, if the optional argument has a value of '1', it's hard to read which option is present. If you're forced to do this with old code, use values that read well on the calling side, if possible.
#no so good createIndex( $table, $name, $keyfield, undef, undef, 1); createIndex( $table, $name, $keyfield, undef, 75); #slightly better createIndex( $table, $name, $keyfield, undef, undef, 'ignore_dup_keys' + ); createIndex( $table, $name, $keyfield, undef, 'fillfactor=75' );
If you have control, and there are optional element, it's best to use a hashref. Even if all the args are necessaary, if the number of elements goes over 3 or 4, a hashref is a good idea to improve readability.
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|
|---|