Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

And now for something completely different...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11127703 use warnings; no warnings qw( qw ); use Search::Dict; @ARGV = qw( 1,2,5,6,9,10,41-56 1 4 42 17 ); my $file = join '', map "$_\n", split /,/, shift; open my $fh, '<', \$file or die; for my $n ( @ARGV ) { look $fh, $n, { comp => sub { $_[0] <=> $_[1] }, xfrm => sub { $_[0] =~ s/\d+-//r }, }; my $have = <$fh>; my $not = (defined $have and $have =~ /(\d+)-(\d+)/ ? $1 <= $n <= $2 : $have == $n) ? '' : ' no +t'; print "$n is$not in set\n"; }

Outputs:

1 is in set 4 is not in set 42 is in set 17 is not in set

In reply to Re: Comparing a value to a list of numbers by tybalt89
in thread Comparing a value to a list of numbers by g_speran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

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












    Results (69 votes). Check out past polls.

    Notices?