Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Comparing a value to a list of numbers

by Anonymous Monk
on Jan 29, 2021 at 18:51 UTC ( #11127657=note: print w/replies, xml ) Need Help??


in reply to Comparing a value to a list of numbers

Seriously ... List::Util is your friend. (Even if you just "steal" a particular algorithm from it.) There's no reason to do something over if someone else has already done it.
  • Comment on Re: Comparing a value to a list of numbers

Replies are listed 'Best First'.
Re^2: Comparing a value to a list of numbers
by Anonymous Monk on Jan 29, 2021 at 19:49 UTC
    Please give an example (in perl code) of hose List::Util can be used to solve the OP's problem. Otherwise your "help" is just a waste of space and a waste of everybody's time.
      Please give an example (in perl code) of hose List::Util can be used to solve the OP's problem
      use warnings; use strict; use List::Util 'uniq'; my @given = (1,2,5,6,9,10,41..56); my @check = (3,4,9,11,48,102); my $c = uniq(@given); for(@check) { push(@given, $_); print "$_ is in the list\n" unless $c + 1 == uniq(@given); pop(@given); } __END__ Outputs: 9 is in the list 48 is in the list
      List::Util::uniq() utilizes the hash lookup referred to elsewhere in this thread.
      Some efficiency is lost in this script because uniq() has to generate the hash every time it is called.
      It would be more efficient if the perl code itself created the hash (just once), and then re-used that hash for each number that needs to be checked.

      Perhaps anonymous had some other List::Util routine in mind.

      Cheers,
      Rob

      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-05-07 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (91 votes). Check out past polls.

    Notices?