in reply to (Ovid) Re: Newbie realisation about
in thread Newbie realisation about
for ( 0 .. 19 ) { print "$_\n"; }
... with the reminder that ( 0 .. 1000000 ) would put an undue strain on your machine's memory as it generates all million (plus one) numbers in a list. And if you have two nested loops, you have to do the 'hot potatoe' thing with $_ so that its value doesn't get overwritten.
It's a matter of preference .. I would rather just writefor ( 0..7 ) { my $Col = $_; # Eek! Save $_ otherwise this value is lost for ( 0..7 ) { # Do something in an 8x8 matrix. if ( $Matrix[ $Col ][ $_ ] == 4 ) ... } }
But that's my years of C programming colouring my view of Perl.for ( my $Col = 0; $Col < 8; $Col++ ) { for ( my $Row = 0; $Row < 8; $Row++ ) { # Do something in an 8x8 matrix. if ( $Matrix[ $Col ][ $Row ] == 4 ) ... } }
--t. alex
"Of course, you realize that this means war." -- Bugs Bunny.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re(3): Newbie realisation about
by Ovid (Cardinal) on Feb 02, 2002 at 08:16 UTC | |
|
Re (tilly) 3: Newbie realisation about
by tilly (Archbishop) on Feb 03, 2002 at 03:43 UTC |