in reply to One-liners: Conditionals in Loops
What I don't like about the feature is that when the logic gets more complex, you need to completely take the loop apart and rewrite. The more complex you let it get before that rewrite happens, the more painful the rewrite is. But if you want to keep it as a one-liner now, then I suggest that you write it like this:
(I find that clearer than using boolean operators. Yes, they work, but I have to think more about what the author is trying to do...YMMV though.)print "$_\n" for grep /pattern/, @arr;
UPDATE: I realized that I was unclear about something. Ruby does not have an inline form of the basic for loop like it does if, unless, while and until. But the ones that it does do inline it allows you to stack as many deep as you want.
UPDATE 2: My beliefs have changed in view of TheDamian's response...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: One-liners: Conditionals in Loops
by TheDamian (Vicar) on Nov 05, 2003 at 04:12 UTC |