Re: Compressing a statement if X for Y to one line

2007-12-09 Thread John W . Krahn
On Sunday 09 December 2007 17:05, Jeff Pang wrote: > > On Dec 10, 2007 6:23 AM, yitzle <[EMAIL PROTECTED]> wrote: > > > > Can the following code be done without any "code blocks"? ^ > > do {print "$_\n" if($_ > 3);} for (0..5); > > > > Thi

Re: Compressing a statement if X for Y to one line

2007-12-09 Thread yitzle
Thanks for the replies! On 12/9/07, John W. Krahn <[EMAIL PROTECTED]> wrote: > $_ > 3 and print "$_\n" for 0 .. 5; This one instantly appealed to me for some reason. I love it! Reminds me of the Python version of the if operator (? :). (I started reading Dive Into Python this last week. Strong ty

Re: Compressing a statement if X for Y to one line

2007-12-09 Thread Jeff Pang
On Dec 10, 2007 6:23 AM, yitzle <[EMAIL PROTECTED]> wrote: > Can the following code be done without any "code blocks"? > do {print "$_\n" if($_ > 3);} for (0..5); > > This doesn't work: > print "$_\n" if($_ > 3) for (0..5); > $ perl -le 'print join" ",grep {$_>3} 0 ..5' 4 5 -- To unsubscribe, e-

Re: Compressing a statement if X for Y to one line

2007-12-09 Thread John W . Krahn
On Sunday 09 December 2007 14:23, yitzle wrote: > > Can the following code be done without any "code blocks"? > do {print "$_\n" if($_ > 3);} for (0..5); $_ > 3 and print "$_\n" for 0 .. 5; print map $_ > 3 ? "$_\n" : (), 0 .. 5; John -- use Perl; program fulfillment -- To unsubscribe, e-

Compressing a statement if X for Y to one line

2007-12-09 Thread yitzle
Can the following code be done without any "code blocks"? do {print "$_\n" if($_ > 3);} for (0..5); This doesn't work: print "$_\n" if($_ > 3) for (0..5); In Python, you'd do something similar to: print "$_\n" for (0..5) if($_ > 3); but that doesn't work either. If there a way to loop through a