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.
In reply to Re: (Ovid) Re: Newbie realisation about
by talexb
in thread Newbie realisation about
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |