From: Dan Sugalski Date: 2002-08-29T01:18:07+09:00 Subject: Re: Converting Perl scripts to Ruby? At 6:23 PM +0900 8/28/02, Tim Hammerquist wrote: >Thank you for explaining. I think I understand what you mean >now. No, I suppose Perl doesn't have any way to truly perform >anything 10 times without a "surrogate" var. The closest I can >get off the top of my head is: > > foreach (1..10) { do_something } > >Yes, it sets the implicit $_, but even Ruby's "(10).times" >creates an anonymous Fixnum. > >The biggest waste in the above code is that it creates a >temporary anonymous list of 10 actual integers over which to >iterate, all of which are tossed away, their value never actually >processed. That turns out not to be the case. Constant ranges or lone arrays in a foreach generate an iterator, so there's no temporary list. There's code to make the 'fake' values in the constant range iterator real if you reference them in ways that would require them persist outside the foreach block. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk