programming-examples/perl/Subroutine/Returning arrays from subroutines.pl
2019-11-15 12:59:38 +01:00

24 lines
359 B
Perl

#!/usr/bin/perl -w
# Checks for desired return type.
@ar = get_value();
print "Wanted array. Got back: @ar\n";
$v = get_value();
print "Wanted scalar. Got back: $v\n";
sub get_value {
my(@array) = (1, 2, 3);
my($val) = 55;
if (wantarray) {
return @array;
} else {
return $val;
}
}