Tags Perl

Guess what the following code prints. Quick !

print foo();

sub foo
{
  return reverse "simpson";
}
Did you guess correctly ? Because I didn't and it cost me a half an hour of debugging (my example was much more complicated, with foo reversing some arguments, and being pushed to an array). Why does this print "simpson" ? I guess there is an explanation, because of the list-context-behavior of reverse. In any case, this is quite unexpected and hence annoying

Comments

comments powered by Disqus