Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Comparing a value to a list of numbers

by jcb (Parson)
on Jan 31, 2021 at 04:50 UTC ( #11127703=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl
    # -*- CPerl -*-
    ...
    foreach (@ARGV) {
      print $_, search($Set, $_) ? ' is' : ' is not', " in the set\n";
    }
    
  2. or download this
    $ ./bsearch.pl 1,2,5,6,9,10,41-56 1 4 42 17
    $Set = [[1,2],[5,6],[9,10],[41,'56']];
    ...
    4 is not in the set
    42 is in the set
    17 is not in the set
    
  3. or download this
    $ ./bsearch.pl 1,2,11-16,6,7,19,9,5-8,13,14,15,4 1 2 3 4 5 8 9 10 11 1
    +2 16 17 18 19 20
    $Set = [[1,2],[4,9],[11,16],19];
    ...
    18 is not in the set
    19 is in the set
    20 is not in the set
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11127703]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-06-15 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (70 votes). Check out past polls.

    Notices?