### Thread: Problem In For Loop (logic Problem )

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
May 2013
Posts
1
Rep Power
0

#### Problem In For Loop (logic Problem )

for example

input file

link1 myco1 x y

link1 myco2 w z

link2 myco1 a b

link2 myco2 c d

.

'

'

if (y-a)&&(z-c)< threshold

print as following

link1 x b

link1 w d

<CODE>
use strict;
use warnings;

my \$JOB = \$ARGV[0];
my \$threshold = \$ARGV[1];

my \$fh = "/home/Desktop/merge/\$JOB/src/link.txt";

open (INFILE_link,"<\$fh") or die \$!;

my @file_array;

while (my \$line = <INFILE_link>) {
chomp \$line;
my @line_array = split(/\s+/, \$line);
push (@file_array, \@line_array);
}

my \$arraySize_link = scalar (@file_array);
my \$ix=1;
my (\$i, \$a, \$b, \$c, \$d, \$x, \$w, \$y, \$z, \$ta, \$tb, \$tc, \$td);

\$a= \$b= \$c= \$d= \$x= \$w= \$y= \$z= \$ta = \$tb =\$tc =\$td= 0;
#open (FILE,'>'."\$fh");
for ( \$i=0; \$i<\$arraySize_link; \$i+=2)
{
\$ta = \$file_array[\$i][2];
\$tb = \$file_array[\$i][3];
\$tc = \$file_array[\$i+1][2];
\$td = \$file_array[\$i+1][3];

if (\$a=\$b=\$c=\$d=\$x=\$w=\$y=\$z = 0)
{

\$a = \$x = \$ta ;
\$b = \$y = \$tb ;
\$c = \$w = \$tc ;
\$d = \$z = \$td ;
last;
}
if ( (\$ta-\$a) < \$threshold && (\$tc-\$c) < \$threshold)
{
# copy tabcd to abcd
\$a = \$ta ;
\$b = \$tb ;
\$c = \$tc ;
\$d = \$td ;
}
else
{

print "\$file_array[\$i][0] \$file_array[\$i][2] \$file_array[\$i+2]
+[3]\n\$file_array[\$i+1][0] \$file_array[\$i+1][2] \$file_array[\$i+3][3]\n
+";

\$a = \$x = \$ta ;
\$b = \$y = \$tb ;
\$c = \$w = \$tc ;
\$d = \$z = \$td ;

}
} # end of for loop

if (\$a=\$b=\$c=\$d=\$x=\$w=\$y=\$z != 0)
{

print "\$file_array[\$i][0] \$file_array[\$i][2] \$file_array[\$i][3
+]\n\$file_array[\$i+1][0] \$file_array[\$i+1][2] \$file_array[\$i+1][3]\n";

</CODE>

MY INPUT

MVRS has asked for the wisdom of the Perl Monks concerning the following question:
Reputation: 3
hi friends , here a perl script written by me to merge link files

my input(link) is as following

link1 myco1 16 13013 color=chr1

link1 myco2 7419028 7432025 color=chr1

link2 myco1 13016 31245 color=chr1

link2 myco2 7432026 7450255 color=chr1

link3 myco1 31569 50386 color=chr1

link3 myco2 7450876 7469693 color=chr1

link4 myco1 53241 82019 color=chr1

link4 myco2 7472518 7501295 color=chr1

link5 myco1 82667 85039 color=chr1

link5 myco2 7511397 7513769 color=chr1

link6 myco1 85052 162535 color=chr1

link6 myco2 7513770 7591243 color=chr1

OUTPUT
link1 16 31245

link1 7419028 7450255

link2 13016 50386

link2 7432026 7469693

link3 31569 82019

link3 7450876 7501295

link4 53241 85039

link4 7472518 7513769

link5 82667 162535

link5 7511397 7591243

link6 85052

link6 7513770

I FOUND HERE IN THE FOR LOOP THE LOOP EXCEEDS BEYOND THE LOOP VALUE , CAN SOME BODY HELP ME FIXING THIS LOGIC
2. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
May 2013
Posts
1
Rep Power
0

#### Problem In For Loop

Alright so we're working on a school assignment and we have to make a roller coaster. the problem is the loop pinches and the marble rolls and either sticks or falls back the other way.