locate an entry and related information in the file

Does any one have an good idea  to implement following question in perl effectively.
suppose there is a file the format is:

metrics        range

entry1           0-12
entry2           0-56
entry3           0.2-13.4

when the program gets an entry name and its value from user(e.g. "entry2   24"),it can locate this entry and its range in the file.Then check if the given value is within range. and report "success" or "fail" to the user.
Who is Participating?
alamoConnect With a Mentor Commented:
Sorry about that then... here's my solution to it, based on the file format you posted.. if your solution is as good or better then just reject it and ask them to delete this question

open(IN, "<metrics.dta") || die("Open failed - $!\n");
while (<IN>) {
 # data format: <entryname>   <lowerbound>-<upperbound>
 if (/^([a-zA-Z0-9]+)\s+(-*[\d\.]+)-(-*[\d\.]+)\s*$/) {
 else {
  print "Bad line in metrics file, ignored: $_\n";

Then the test routine:

sub TestMetric {
 my $value = pop;
 my $metric = pop;
 if (!exists $lowerbound{$metric}) {
  print "No metric '$metric' found\n";
 elsif ($lowerbound{$metric} <= $value && $value <= $upperbound{$metric}) {
  print "true\n";
 else {
  print "false\n";

Hope this helps..
Before I give you some code, would you please confirm that this is not an assignment for any class? Posting class assignments is against EE rules.

(I haven't heard of any classes giving assignments in perl, but the nature of the problem and the way it's phrased is very assignment-like, and I am just making sure).

tianAuthor Commented:
It's difinitely not.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

tianAuthor Commented:
It's difinitely not. In fact, I already implemented it:
read file one line at one time,then use "split" to parse it and commpare corresponding items with user input.....  
tianAuthor Commented:
thank you very much.
 But how about if metric user given is just part of a compound metric in the file.
for example:

metric_name       range
m1                       1~12
m3+m4                23~34
m7                    45~23
what the user input is " (m3  3),(m1 19), (m4 23)..." and the program can make a report indicate the "false" or true" for each metric entry in the file
tianAuthor Commented:
Sould I post modified question again?
I just now saw your comments... yes, the new question is a different than this one because the compound metrics means you have to save the inputs and loop through the metrics, calculating each one. All the code changes.

I can't take a look at it quite at this moment unfortunately, if the new question is still unanswered later I will answer it, in any event good luck!
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.

All Courses

From novice to tech pro — start learning today.