try it
use strict;
use warnings;
sub mySub{
return undef;
}
my @arr = (1,2,3,4,5,6,7,8,9);
my @arr2 = map(&mySub, @arr);
print @arr." ".@arr2;
If you need to get a list containing undefs, you need to explicitly specify undef. The fact is that the map calls your mySub in the context of the array (check what exactly you want to get from this unit). return statement essentially returns an empty list every time you call sub, which results in an empty array as a whole
source
share