rigadon
04-13-2005, 09:11 AM
Hi
Is there some way in which the return type (scalar/array/etc) can be changed depending on what the calling code is expecting? For instance:
# case 1
my @one_two = &config(qw(one two));
print "@one_two\n";
# case 2
my $installation = &config(qw(installation))
print "$installation\n";
exit;
sub config
{
my (@params) = @_;
my %default = (
installation => 'TPG',
one => 'nothing important',
two => 'nothing important again',
);
return map { $default{$_} } @params;
}
The output of which would be:
nothing important nothing important again
1
In case 2 the array is returned as a scalar as that is what the calling code is expecting. Is there some way to determine what is type expected and thus manipulate the config function to return this type?
Thanks
Jay
Is there some way in which the return type (scalar/array/etc) can be changed depending on what the calling code is expecting? For instance:
# case 1
my @one_two = &config(qw(one two));
print "@one_two\n";
# case 2
my $installation = &config(qw(installation))
print "$installation\n";
exit;
sub config
{
my (@params) = @_;
my %default = (
installation => 'TPG',
one => 'nothing important',
two => 'nothing important again',
);
return map { $default{$_} } @params;
}
The output of which would be:
nothing important nothing important again
1
In case 2 the array is returned as a scalar as that is what the calling code is expecting. Is there some way to determine what is type expected and thus manipulate the config function to return this type?
Thanks
Jay