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.