I cannot reproduce your problem in 5.6.1. What doesn't compile about that latter statement? It looks fine logically and works fine on my system (taking liberty with the nature of your function and the data):
#!/usr/bin/perl
use Data::Dumper;
sub get_day_name {
return "first" if $_[0] =~ /one/;
return "second" if $_[0] =~ /two/;
return "third" if $_[0] =~ /three/;
return;
}
print Dumper {map {$_ => get_day_name($_)} <DATA>};
__DATA__
one
two
three
Results:
$VAR1 = {
'two
' => 'second',
'three
' => 'third',
'one
' => 'first'
};
You probably want a chomp in your map though to get rid of those newlines. |