tomatocans
asked on
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(/;/,$fiel ds[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|$co unt[$numbe r]|$3|$cou nt[$number ]|$4|$coun t[$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.
ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL
Have the following loop reading input:
while(<IN>){
@anomalies=split(/;/,$fiel
$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
$3="YES";
@count[$number];
}
else(@anomalies[i]="ALT DEV/EXCURSION FROM ASSIGNED"){
$4="YES";
$count++;
}
}
print OUT "$1|$count[$number]|$2|$co
}
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.
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]).
$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]).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No it is the postion in the string not the count.
I apologize.
I apologize.
ASKER
The output should return the what position in the string the anomaly appears.
ASKER
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
Sorry about the confusion
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
Sorry about the confusion
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(/;/,$fiel ds[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
#!/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(/;/,$fiel
@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
ASKER
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.
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.
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.
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.
ASKER
The answer is not it will not be contained twice
in the substring
in the substring
here is your solution....
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(/\;/,$fie lds[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{'th ree'}|$fou r|$count{' four'}\n";
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(/\;/,$fie
$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|$
ASKER
Adjusted points from 38 to 50
ASKER
Thanks
ASKER
ALT DEV/EXCURSION FROM ASSIGNED;ACFT EQUIPMENT PROBLEM/CRITICAL
Have the following loop reading input:
while(<IN>){
@anomalies=split(/;/,$fiel
$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
$3="YES";
@count[$number];
}
else(@anomalies[i]="ALT DEV/EXCURSION FROM ASSIGNED"){
$4="YES";
@count[$number];
}
}
print OUT "$1|$count[$number]|$2|$co
}
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.