Including the OOPier and LISPier parts. And I don't think like that.
Perl programmers should know
$_
. Consider $x = my_subroutine()
. We see where the return value goes here, it goes to $x
. Now, consider my_subroutine()
. You know there's a return value. Now, where does it go? It goes into $_
. Which means you can follow my_subroutine();
with print ;
with no problem, because the first line drops it into $_ and the second line picks it up. New Perl programmers get infuriated by that magic until they understand it.Ruby has a lot of magic. I understand very little of it.
This is making me cross. And it will make me cross until I start to understand the wizardry of it.
I might be misunderstanding something here but in the general case calling my_subroutine() without assigning to any variable will NOT assign the return value to $_.
ReplyDeleteThe specific case might be wrong, and for that I am sorry, but you know that most of the cooler uses of $_ involve the string "$_" rarely occurring in the code, which brings experienced Perl programmers much joy, but gives inexperienced Perl programmers much frustration, because they can't see what's going on.
ReplyDeleteThere's cool stuff going on with Ruby, to be sure, but right now, I can't see how it does what it does, and that has been frustrating for me.