# Loop That Pa

Have input for \$fields[11] like so:
ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL

Have the following loop reading input:

while(<IN>){

@anomalies=split(/;/,\$fields[11]);
\$number=0;
\$i=1;
#LIST OF ANOMALIES
\$1="NO";   #ACFT EQUIPMENT PROBLEM/CRITICAL
\$2="NO";   #ACFT EQUIPMENT PROBLEM/LESS SEVERE
\$3="NO";   #ALT DEV/EXCURSION FROM ASSIGNED
\$4="NO";   #ALT DEV/OVERSHOOT ON CLB OR DES
for(\$i;\$i< 4;\$i++){
\$number++;
if(@anomalies[i]="ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$1="YES";
@count[\$number];
}
elsif(@anomalies[i]="ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$2="YES";
@count[\$number];
}
elseif(@anomalies[i]="ACFT EQUIPMENT PROBLEM/LESS SEVERE"){
\$3="YES";
@count[\$number];
}
else(@anomalies[i]="ALT DEV/EXCURSION FROM ASSIGNED"){
\$4="YES";
\$count++;
}
}

print OUT "\$1|\$count[\$number]|\$2|\$count[\$number]|\$3|\$count[\$number]|\$4|\$count[\$number]";

}

The line of input in the example should print

NO|0|YES|2|NO|0|YES|1

How would u correct the code to properly produce the output.

###### Who is Participating?

x

Commented:
based on my above assumption, here is a working solution...

NOTE: you cannot assign values yourself to \$1,\$2 etc.. since these are PERL read-only variables.

================tcans.pl
#!/usr/local/bin/perl

\$fields[11]="ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL";

@anomalies=split(/\;/,\$fields[11]);
\$number=0;
\$i=1;
#LIST OF ANOMALIES
\$one="NO";   #ACFT EQUIPMENT PROBLEM/CRITICAL
\$two="NO";   #ACFT EQUIPMENT PROBLEM/LESS SEVERE
\$three="NO";   #ALT DEV/EXCURSION FROM ASSIGNED
\$four="NO";   #ALT DEV/OVERSHOOT ON CLB OR DES

\$count{'one'}=0;
\$count{'two'}=0;
\$count{'three'}=0;
\$count{'four'}=0;
foreach(@anomalies){
if (\$_ eq "ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$one="YES";
\$count{'one'}++;
}elsif (\$_ eq "ACFT EQUIPMENT PROBLEM/LESS SEVERE"){
\$two="YES";
\$count{'two'}++;
}elsif (\$_ eq "ALT DEV/EXCURSION FROM ASSIGNED"){
\$three="YES";
\$count{'three'}++;
}elsif (\$_ eq "ALT DEV/OVERSHOOT ON CLB OR DES"){
\$four="YES";
\$count{'four'}++;
}
}

print "\$one|\$count{'one'}|\$two|\$count{'two'}|\$three|\$count{'three'}|\$four|\$count{'four'}\n";
0

Author Commented:
Have input for \$fields[11] like so:
ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL

Have the following loop reading input:

while(<IN>){

@anomalies=split(/;/,\$fields[11]);
\$number=0;
\$i=1;
#LIST OF ANOMALIES
\$1="NO";   #ACFT EQUIPMENT PROBLEM/CRITICAL
\$2="NO";   #ACFT EQUIPMENT PROBLEM/LESS SEVERE
\$3="NO";   #ALT DEV/EXCURSION FROM ASSIGNED
\$4="NO";   #ALT DEV/OVERSHOOT ON CLB OR DES
for(\$i;\$i< 4;\$i++){
\$number++;
if(@anomalies[i]="ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$1="YES";
@count[\$number];
}
elsif(@anomalies[i]="ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$2="YES";
@count[\$number];
}
elseif(@anomalies[i]="ACFT EQUIPMENT PROBLEM/LESS SEVERE"){
\$3="YES";
@count[\$number];
}
else(@anomalies[i]="ALT DEV/EXCURSION FROM ASSIGNED"){
\$4="YES";
@count[\$number];
}
}

print OUT "\$1|\$count[\$number]|\$2|\$count[\$number]|\$3|\$count[\$number]|\$4|\$count[\$number]";

}

The line of input in the example should print

NO|0|YES|2|NO|0|YES|1

How would u correct the code to properly produce the output.

0

Commented:
given that
\$field[11] contains ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL

& also give that

\$1 looks for ACFT EQUIPMENT PROBLEM/CRITICAL
\$2 looks for ACFT EQUIPMENT PROBLEM/LESS SEVERE
\$3 looks for ALT DEV/EXCURSION FROM ASSIGNED
\$4 looks for  ALT DEV/OVERSHOOT ON CLB OR DES

shouldn't the output be....

NO|1|YES|0|NO|1|YES|0

??

i am assuming that the numbers are the count of times that each sub-string has been found in the mail string (\$field[11]).
0

Author Commented:
No it is the postion in the string not the count.
I apologize.
0

Author Commented:
The output should return the what position in the string the anomaly appears.

0

Author Commented:
In the example

ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL

ALT DEV/EXCURSION FROM ASSIGNED is first
ACFT EQUIPMENT PROBLEM/CRITICAL is second

so the ouput should be

YES|2|NO|0|YES|1|NO|0

0

Commented:
If I understand your question correctly, this may be what you are looking for:

#!/usr/local/bin/perl

\$lst  = "ACFT EQUIPMENT PROBLEM/CRITICAL";
\$lst .= ":ACFT EQUIPMENT PROBLEM/CRITICAL";
\$lst .= ":ACFT EQUIPMENT PROBLEM/LESS SEVERE";
\$lst .= ":ALT DEV/EXCURSION FROM ASSIGNED";

@a = split /:/, \$lst;
\$c[0] = "ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL";
\$c[1] = "ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL";
\$c[1] .= "; ;ALT DEV/OVERSHOOT ON CLB OR DES";
\$c[3] = " ; ; ;ALT DEV/EXCURSION FROM ASSIGNED";
\$rst = "";

%b = ();
# while(<IN>){
for \$j (0..\$#c) {
# @anomalies=split(/;/,\$fields[11]);
@anomalies=split(/;/,\$c[\$j]);
for \$i (0..\$#anomalies) {
if ("\$anomalies[\$i]" eq "\$a[\$i]") { ++\$b{'YES'}[\$i];
} else { ++\$b{'NO'}[\$i]; }
}
}
# }
for \$i (0..3) {
if (\$b{'YES'}[\$i] > 0) {
if (\$rst) { \$rst .= "|YES|" . \$b{'YES'}[\$i];
} else    { \$rst  = "YES|" . \$b{'YES'}[\$i]; }
} else {
if (\$rst) { \$rst .= "|NO|0"; } else { \$rst = "NO|0"; }
}
}
# print OUT "\$rst\n";
print "\$rst\n";

# The line of input in the example should print
# NO|0|YES|2|NO|0|YES|1

The output is
NO|0|YES|2|NO|0|YES|1

0

Author Commented:
Sorry this is too hard coded the input
i have has 66,000 lines with

30 types of anomalies.

I agree this is a solution for the
specific example but
I am look for something like mansher
was doing but with position instead
of count.

In your example geotiger I would
need to much hard coding for the \$c[N]
area.

Is there a proper solution within the framework
that Maneshr was exploring. Just substituting position for count.
0

Commented:
tomatocans,

i have a Q. can the string contain the same substring twice ??

Eg.
ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL;ALT DEV/EXCURSION FROM ASSIGNED

if yes, what should the result be in this case since the sub-string ALT DEV/EXCURSION FROM ASSIGNED appears at position 1 and 3!!

if the answer is no, i have a solution ready for you.
0

Author Commented:
The answer is not it will not be contained twice
in the substring
0

Commented:

i have had to make some very small changes to the original script to make it work.

========tcans.pl
#!/usr/local/bin/perl

\$fields[11]="ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL";
@anomalies=split(/\;/,\$fields[11]);
\$number=0;
\$i=1;
#LIST OF ANOMALIES
\$one="NO";   #ACFT EQUIPMENT PROBLEM/CRITICAL
\$two="NO";   #ACFT EQUIPMENT PROBLEM/LESS SEVERE
\$three="NO";   #ALT DEV/EXCURSION FROM ASSIGNED
\$four="NO";   #ALT DEV/OVERSHOOT ON CLB OR DES

\$count{'one'}=0;
\$count{'two'}=0;
\$count{'three'}=0;
\$count{'four'}=0;
#foreach(@anomalies){
foreach(\$[ .. \$#anomalies){
if (\$anomalies[\$_] eq "ACFT EQUIPMENT PROBLEM/CRITICAL"){
\$one="YES";
\$count{'one'}=(\$_+1);
}elsif (\$anomalies[\$_] eq "ACFT EQUIPMENT PROBLEM/LESS SEVERE"){
\$two="YES";
\$count{'two'}=(\$_+1);
}elsif (\$anomalies[\$_] eq "ALT DEV/EXCURSION FROM ASSIGNED"){
\$three="YES";
\$count{'three'}=(\$_+1);
}elsif (\$anomalies[\$_] eq "ALT DEV/OVERSHOOT ON CLB OR DES"){
\$four="YES";
\$count{'four'}=(\$_+1);
}
}

print "\$one|\$count{'one'}|\$two|\$count{'two'}|\$three|\$count{'three'}|\$four|\$count{'four'}\n";

0

Author Commented:
Adjusted points from 38 to 50
0

Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.