Chas Owens wrote:
No, that is almost always better written as
for my $element (@array) {}
You should only use a range if you want to iterate a specific number
of times or you want to iterate over that range. Using the position
of last the last element in an array is a big clue that you really
want to iterate over an array, not a range.
Sometimes you want the index to the array:
sub shuffle {
my $deck = shift @_;
for my $i ( 0 .. $#{ $deck } ){
my $j = int( rand( scalar( @{ $deck } )));
( $deck->[$i], $deck->[$j] ) = ( $deck->[$j], $deck->[$i] );
}
}
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/