Mark M Huntress wrote:
I want to nest a for loop in a for loop in a while loop, and I can't
even get just the first nesting to work yet. Here is the relevant part
of my scripting.
open(XYZ,"$ARGV[0]ready.xyz");
Better as:
open XYZ, '<', "$ARGV[0]ready.xyz"
or die "Cannot open '$ARGV[0]ready.xyz' because: $!";
#while (<XYZ>) {
#chomp($_);
for ($z = 0, $z<= $#sortedstart, $z++) {
You are iterating over a list of three numbers. If @sortedstart is
empty then you get:
for $_ ( 0, 0, 0 ) {
If @sortedstart is NOT empty then you get:
for $_ ( 0, 1, 0 ) {
What you probably want is:
for my $z ( 0 .. $#sortedstart ) {
for ($i = $sortedstart[$z], $i<= $sortedend[$z], $i++) {
Again, you are iterating over a list of three numbers. If
$sortedend[$z] is less than $i you get:
for $_ ( $sortedstart[$z], 0, $sortedstart[$z] ) {
If $sortedend[$z] is NOT less than $i you get:
for $_ ( $sortedstart[$z], 1, $sortedstart[$z] ) {
What you probably want is:
for my $i ( $sortedstart[ $z ] .. $sortedend[ $z ] ) {
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/