Operating System - HP-UX
1828480 Members
3099 Online
109978 Solutions
New Discussion

Re: Need a Perl script for checking the boundary values

 
SOLVED
Go to solution
kumar143
Occasional Contributor

Need a Perl script for checking the boundary values

Need a Perl script for checking the condition's for each measure value from the test data. Perl script should read from the input file for each measure and check the condition from the test data and give appropriate results saying "Passed" or Failed
if the condition is satisfied then it is "Passed" else "Failed"

Input file:

1.Measure1 value>0
2.Measure2 Value>0 and Value<100
3.Measure3 Value>0,Value(Measure 1+ Measure 2 + Measure 3)< Measure4

Test data:
Measure1 100
Measure2 120
Measure3 50
Measure4 300

Result:

1.Measure1 value>0 " Passed"
2.Measure2 Value>0 and Value<100 "Failed"
3.Measure3 Value>0,Value(Measure 1+ Measure 2 + Measure 3)< Measure4 "Passed"

Thanks in adavance
Kumar




4 REPLIES 4
Hein van den Heuvel
Honored Contributor

Re: Need a Perl script for checking the boundary values

Hmmm,

The 'input file'..
Is that to be interpreted, or are those just the rules to be coded up once?
If interpretted...
This feels more like 'work' to be done for a fee, rather then friendly advice.

But in case someone is nice enough to try to help, please be ready to provide aditional input.
- What is the quality and quantity of the rules to be ready for?
- How may?
- How complex?
- Which 'formulas' SUM only?
- Which variables? Just those listed?
- What values? Integer, Floating Point? Text? Date & Time?

The "test data":
Just one set, or a lists of them
How delimited? Always all measurement present? Always in the same order (such that the script and look at say 'Measure4' and know all data has been seen?

The flip/flop between Measure3 and Measure4
is very nasty... Is Measure3 allowed to be zero or negative? According to the current rules it can be. That "comma" after Value>0 for Measure3, is that an AND or OR?

You may be able to make an awk or perl script clear and clean enough to make the specification be the program?

The followin awk script may, or might not do what you request.

/Measure1/ { Measure1 = value = $2;
print "value>0",
"Measure1", (value>0)? "\"Passed\"" : "\"Failed\""
}

/Measure2/ { Measure2 = value = $2;
print "value>0 and Value<100",
"Measure2", (value>0 && value<100)? "\"Passed\"" : "\"Failed\""
}

/Measure3/ { Measure3 = value = $2;
}

/Measure4/ { Measure4 = $2; value = Measure3;
print "Value>0,Value(Measure 1+ Measure 2 + Measure 3)< Measure4",

"Measure3", (value>0 && (Measure1 + Measure2 + Measure3) < Measure4)? "\"Passed\"" : "\"Failed\""
}

It works for me:

$ awk -f x.awk x
value>0 Measure1 "Passed"
value>0 and Value<100 Measure2 "Failed"
Value>0,Value(Measure 1+ Measure 2 + Measure 3)< Measure4 Measure3 "Passed"

fwiw,
Hein.


James R. Ferguson
Acclaimed Contributor

Re: Need a Perl script for checking the boundary values

Hi:

I'm of the same mind aa Hein: "This feels more like 'work' to be done for a fee, rather then friendly advice."

So, that said, send $$$ or at least show us *what* you have tried and *where* you are stuck. Aret you are looking for a platform agnostic solution (?) or is it that this is really a piece that you need to add to an existing piece of Perl code; hence the language-specific request?

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: Need a Perl script for checking the boundary values

>Need a Perl script for checking the conditions for each measure value from the test data. Perl script should read from the input file for each measure

As Hein and JRF mention, it seems you are trying to write a general purpose expression interpreter. I've seen something like this for glance's filters in displaying data.
If not trying to evaluation random user input, it might be easy to just write your 4 programs.

Unfortunately neither awk (or perl?) have an eval operator to interpret expressions.
Hein van den Heuvel
Honored Contributor
Solution

Re: Need a Perl script for checking the boundary values

The awk suggestion I made is a little 'cute' in that the decision text, closely matched the decision code.
But this is only seen in a fixed-font.
So here is it again, attached as a text file.
Hein.