You could change your subroutine calls slightly to use named arguments by passing a hash rather than a list. (I'm assuming that your mixture of $ and & is a typo and that you are using named subroutines rather than code references.) Something like this code structure might fit the bill:-
...
my $yes_no = 1;
...
if ( $error_cond eq 'too long' )
{
too_long();
}
elsif ( $error_cond eq 'no name' )
{
no_name();
}
elsif ( $error_cond eq 'cap err' )
{
cap_err();
}
else
{
fallback();
}
...
sub too_long
{
my %args = ( length => $len, type => q{Some type} );
HTMLFTR( %args );
}
sub no_name
{
my %args = ( request => $req, type => q{Another type} );
HTMLFTR( %args );
}
sub cap_err
{
my %args = ( yes_no => $yes_no, type => q{Odd type} );
HTMLFTR( %args );
}
sub fallback { ... }
sub HTMLFTR
{
my %args = @_;
...
if ( exists $args{ yes_no } )
{
print $args{ yes_no } ? "Yes\n" : "No\n";
}
...
}
By using named parameters it no longer matters what order you pass the arguments or whether some or all are present. I hope this idea is helpful.
|