I found a code fragment in production that I didn't really understand. I tried to narrow it down to a simple example:
%hash = {
'a' => 'apple',
'b' => 'banana',
'c' => 'cherry'
};
my $v = "Hello, " . '+' foreach (keys %hash);
print "Value = \"$v\"\n";
When I run this, the value of $v is the empty string, which is surprising. I'm also curious why . '+' foreach( ... ) doesn't cause an error -- I don't even have an operator between '+' and foreach( ... ), how can this possibly not cause a syntax error?
foreachis also statement modifier (similar to more commonifmodifier, e.g.$y = $z if defined $z;).