Truth. If you are checking in lots of things exist a hashset might be a better way to go:
my %hashset = map { ($_ => undef) } (3,1,4,2,9,0); my $found = exists $hashset{4} || 0; my $not_found = exists $hashset{10} || 0; By setting the value of the hash to be undef, you take up less space than setting it any other value. On Fri, Aug 19, 2016 at 2:15 PM <wagsworl...@yahoo.com> wrote: > But does it need to be an array. Rethink into hash and life could be a > little bit easier... > > Wags ;) > WagsWorld > Hebrews 4:15 > Ph: 408-914-1341 > > On Aug 18, 2016, 19:41 -0700, kp...@freenet.de, wrote: > > Thanks for all the replies. > Yes I found List::Util is a useful toolset. > > > On 2016/8/19 10:00, Chas. Owens wrote: > > The any function from List::Util will also do what you want. > > perldoc List::Util > > http://perldoc.perl.org/List/Util.html#any > > my $found = any { $_ == 4 } (3, 1, 4, 2, 9, 0); # true > my $not_found = any { $_ == 10 } (3, 1, 4, 2, 9, 0); # false > > Which you want depends on the application. The grep function will > return a number between 0 and the size of the list and reads the entire > list. The any function returns the canonical true (a tri-value that > holds "1", 1, and 1.0) or false (a tri-value that holds "", 0, 0.0) > values and stops at the first matching value. The canonical false value > often throws people for a loop as they expect it to be "0" in string > context, but it is "". You may want to say > > my $found = (any { $_ == 10 } (3, 1, 4, 2, 9, 0)) || 0; > > to force it to be 0 instead of the canonical false value. > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >