On Mon, Apr 10, 2006 at 08:38:22PM -0500, Charles K. Clarkson wrote: > Randal L. Schwartz wrote: > > : my $meat; > : $meat = sub { > : $meat = sub { real body of loop here } if $. >= 9; > : }; > : > : $meat->() while <>; > : > : There. Happy? > > Smiling? Yes. Happy? No. > > > : No more tests. And now you'll complain about the > : subroutine call. :) > > Are you kidding? I barely understand it. > > I'm sure it will work, but I hope I don't have to > maintain it.
The $meat = sub { . . . } bit creates an anonymous subroutine, and assigns a reference to it to the $meat variable. This allows you to effectively pass around code within a variable, to be dereferenced when you need it. That sort of behavior, particularly within closures and the like, starts to get into what some call "metaprogramming", where your programs can sorta "write themselves" on the fly. That should give you sort of a beginning on understanding what was just done by Mr. Schwartz. For more, check out the alpaca book (an excellent read, by the way). -- Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ] "The measure on a man's real character is what he would do if he knew he would never be found out." - Thomas McCauley -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>