Pepsi has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I want to write a program in perl where the input is a string which is check against a table with two fields (LOW & HIGH). The low & high field are the ranges. Ex:
-------------- Low---->HIGH A12---->B23 B24---->CCC -----------
So if the input is say 'ABCDEFG234', the program should decide which range the input belongs to? What is the best way to do this?

Edited by Chady -- code tags around example.

Thansk

Replies are listed 'Best First'.
Re: Working with Ranges!!!
by bradcathey (Prior) on Apr 18, 2005 at 12:07 UTC

    And your code so far...?

    I think we would be more helpful if we could see some of your code, and get a better of idea of exactly what it is you are trying to do.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Working with Ranges!!!
by cazz (Pilgrim) on Apr 18, 2005 at 11:58 UTC
    There are probably a zillion ways solve this problem. The first that comes to mind is to convert your ranges to integers, and then its just a simple matter >= and <=.
      Or just use the string equivalents: ge and le.

      Caution: Contents may have been coded under pressure.
Re: Working with Ranges!!!
by tlm (Prior) on Apr 18, 2005 at 13:03 UTC

    The path to what you seek begins here.

    Update: Link fixed. Thanks graff.

    the lowliest monk

      Um... funny thing about how you put in that reference to another node at PM -- specifying the full url so you could add "#sense" to arrive at a specific point in the node...

      When I follow it, my login info gets lost. (I become anonymonk when viewing the referenced node.)

      If you just use [How (Not) To Ask A Question] or [id://172086], rather than hard-coding the full url, the user's login is preserved when following the link -- compare what happens when following your link to what happens with these: How (Not) To Ask A Question (cited by name) and How (Not) To Ask A Question (cited by id://node_id). Or even this (bare node_id plus a label).

      Sadly, it's not possible to append "#target" to any of those citation forms, in order to jump to a specific point in the node, and maybe no one wants to add that capability (maybe for good reason). So just cite the node in the normal way and add a comment that the reader should look for a specific point in the node -- rather than causing the reader to become disoriented.