Hi,
My input file (string) has strings as below
asfd1-asfd2-asfd3
asfd2-asfd3-asfd1
asfd1-asfd4-asfd3
(Create a file named string with above lines as a testcase for program)
each line represents a loop, for example for line-1 asfd1 to asfd2 to asfd3
and back to asfd1,
In that sense line-1 and line-2 represent the same loop.
I was writing a program in perl to detect same loops in the file.
Also i am using array of array for this purpose.
My code is below
#!/usr/bin/perl -w
use Cwd;
my ($i, $j, $k, $l, $m);
my ($firstN, $secondN);
my $mTemp;
my $total = 0;
open(FILE,"string") || die "Unable to open list of FAILED files\n";
while ($line = <FILE>) {
#++$j;
#print $line;
@tmp = split(/-/,$line);
print @tmp;
$total = $total + @tmp;
push @AoA, [split(/-/, $line)];
}
print " Total = $total \n";
print "0 th element $AoA[0][0]\n";
$total = 0;
$notMatched = 0;
for $i ( 0 .. $#AoA ) {
$first = $AoA[$i];
$k = $i + 1;
for $l ($k .. $#AoA)
{
print "for line $i with $l \n";
$second = $AoA[$l];
$firstN = @$first - 1;
$secondN = @$second - 1;
print "firstN $firstN, secondN $secondN \n";
for $j ( 0 .. $firstN ) {
for $m (0 .. $secondN)
{
print "m
$m\n"; #Prob Line 1
print "$AoA[$i][$j]
$AoA[$l][$m]\n"; #Prob Line 2
if($AoA[$i][$j] eq
$AoA[$l][$m]) #Prob block 3
{
print "Found same string $AoA[$i][$j] at [$i][$j]
and [$l][$m]\n" ;
last;
}
}
print "m $m secondN $secondN\n";
#Prob line 4
for $j1 ($j+1 .. $firstN)
{
if($m < $secondN)
{
$m++;
}
else
{
$m = 0;
}
if($AoA[$i][$j1] ne $AoA[$l][$m])
{
$notMatched = 1;
last;
}
}
if($notMatched == 1)
{
last;
}
for $j1 (0 .. $j-1 )
{
if($m < $secondN)
{
$m++;
}
else
{
$m = 0;
}
if($AoA[$i][$j1] ne $AoA[$l][$m])
{
$notMatched = 1;
last;
}
}
}
if($notMatched == 0)
{
printf "Lines $i and $l matched\n";
}
}
}
close(FILE);
Now on running the program for testcase, the lines "#prob line 1" and "#prob
line 2" are executed and they print the values
but eq statement in #prob block 3 not becomes true when it should.
also value of m is not printed at #prob line 4 at all the times
Need help in this regard
Thank You
Brajesh