Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Set Notation Handling

by tradez (Pilgrim)
on Mar 28, 2005 at 18:02 UTC ( [id://442880]=perlquestion: print w/replies, xml ) Need Help??

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

Perl Monks and Math Mongers alike,

   This question is for both of you. I am creating a program that audits parameters for my company's network (about 250 million a day) and checks them against their compliance to a Golden Image. I am figuring out a set way to define ranges of appropriate and valid values and I believe that Set Notation is the best way. Problem is not only must I teach set notation to a bunch of analysts and engineers alike, I need to build a parser against it.

   Question is, has anyone done set notation compliance checking via the magic of perl before, and would you be willing to grace me with your insight.



Tradez
"Every official that come in
Cripples us leaves us maimed
Silent and tamed
And with our flesh and bones
He builds his homes"

- Zach de la Rocha

Replies are listed 'Best First'.
Re: Set Notation Handling
by kvale (Monsignor) on Mar 28, 2005 at 19:18 UTC
    If you are looking for a module to maniptulate sets, try Set::Scalar:
    use Set::Scalar; $s = Set::Scalar->new; $s->insert('a', 'b'); $s->delete('b'); $t = Set::Scalar->new('x', 'y', $z); $u = $s->union($t); $i = $s->intersection($t); $d = $s->difference($t); $e = $s->symmetric_difference($t); $v = $s->unique($t); $c = $s->complement;

    From your other post, however, it seems like you are interested in a more specialized form of set, that is integer ranges or spans. In this case, check out the module Set::IntSpan:

    use Set::IntSpan qw(grep_set map_set); $set_spec = "1-20000"; $set = new Set::IntSpan $set_spec; $set_spec = "1-14192,14194,14196-14221"; $u_set = union $set $set_spec; $i_set = intersect $set $set_spec; $x_set = xor $set $set_spec; $d_set = diff $set $set_spec; $c_set = complement $set;
    For large integral ranges, Set::IntSpan can be a lot more efficient than Set::Scalar.

    -Mark

      This is really a great module, but what would be the simplest way to just say do this:
      $set_spec = '1-4,6,9,12-18'; if ($value IS IN $set_spec){ print "$value is valid\n"; }else{ print "$value is invalid\n"; }


      Tradez
      "Every official that come in
      Cripples us leaves us maimed
      Silent and tamed
      And with our flesh and bones
      He builds his homes"

      - Zach de la Rocha
        Member testing is included in Set::IntSpan. Try this.
        use strict; use Set::IntSpan; + my $set = new Set::IntSpan('1-4,6,9,12-18'); testvalue(3, $set); testvalue(7, $set); + sub testvalue { my $value = shift; my $set = shift; if (member $set $value){ print "$value is valid\n"; }else{ print "$value is invalid\n"; } }
Re: Set Notation Handling
by dragonchild (Archbishop) on Mar 28, 2005 at 18:33 UTC
    Hashes. A hash is a set, so define everything in terms of hashes.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Hrmm, might wanna check the link to know what I meant by "set". I am more talking like I have a Golden Image definition tool, that has an input of type text in html that needs to have a set way to have ranges and values typed in for validation purposes. Set notation being like [0,5000) for a way to say "all values from 0 up to but not including 5000."


      Tradez
      "Every official that come in
      Cripples us leaves us maimed
      Silent and tamed
      And with our flesh and bones
      He builds his homes"

      - Zach de la Rocha
        I have a major in math - I know what you were talking about. Try using a hash before declaring it unusable.

        Remember - you're building a data structure against which to compare items. So, memory is not a major issue for this tool. Thus, translation of [0,5000) is very simple - my %x; $x{$_} = 1 for 0 .. 5000-1;

        Frankly, I think you haven't fully described what it is you're trying to build. You describe an auditing tool for 250M transactions/day in your original post, but now you want to have the auditing criteria be input via a webform. Those aren't very compatible. Auditing tools really should be auditing against the specifications. If your specifications are determined by inputs into a webform, then nothing can help you.

        Being right, does not endow the right to be rude; politeness costs nothing.
        Being unknowing, is not the same as being stupid.
        Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
        Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://442880]
Approved by moot
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-19 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found