sub f ($$) {
my ($one, $two) = @_;
return $one + $two;
}
sub f {
my ($one, $two, @args) = @_;
my $sum = 0;
foreach (@args){
$sum += $_;
}
return $one + $two * $sum;
}
sub f {
my ($one, $two) = @_;
$one = 1 if (! defined $one);
$two = 2 if (! defined $one);
return $one + $two;
}
sub f {
print @_; # can't distinguish whether
# arguments form hash or list
} # (use refs instead)
f(@array, %hash);
|
def f(one, two):
return one + two
f(two=3, one=4) #explicit argument reordering
def f(one, two, *args):
return one + two * sum(args)
def f(one=1, two=2):
return one + two
def f(*args, **keywords):
print args, keywords
f(1, 2, a=4) # "(1, 2) {'a': 4}"
f(*array, **hash)
|