First off, welcome to the Monastery. We hope you enjoy your stay.
Looking at your post, it is hard to understand what you are trying to achieve. Your specification is not so clear. But lets we what we can do...
my @a1 = qw(My name is Andrew); my @a2 = qw(My dog named Andrew);
First off you define two arrays of words, but later only one is used. Perhaps this is a clue...
foreach my $a1 (@a1){ $i++; #print $a1 . "\n"; }
Is this here to count the words in @a1 and set $i? If so we can skip it, and go an easier way later on
First:for($a = 0; $a <= $i; $a++){ Second:for($s = 0; $s <= $i; $s++){ my $d = 0; print $a.$t; print $s.$n; if($a!=$s){ print "Yes.->".$a.$s.$n; last} print "system command \$a $a, then for \$s $s".$n; $d++; } }
OK, so we have two loops, counting from 0 to $i. We have a $d in there that I don't think you use again. Then we print out a line, when the iterators are not equal. All very mysterious.
Perhaps you are trying to compare the words in the lists? I see two word lists, and some initialisation based on the length of one of them. We may not even need nested loops. If that's what you are after, how about something like this...
use strict; use warnings; my @a1 = qw(My name is Andrew); my @a2 = qw(My dog named Andrew); my $i = 0; while ($a1[$i] and $a2[$i]) { # make sure something is in both arrays if ($a1[$i] ne $a2[$i]) { print "system command \$a1 $a1[$i], then for \$a2 $a2[$i]\n"; } else { print "# \$a1 $a1[$i], and \$a2 $a2[$i] are the same\n"; } $i++; }
Like I said, a wild guess. Please do update your specification, so we can help a little more
Cheers,
R.
In reply to Re: how to repeat a if else statement in a nested for loop
by Random_Walk
in thread how to repeat a if else statement in a nested for loop
by ajl412860
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |