Re: if element exists in an array

2016-08-18 Thread kpeng
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

if element exists in an array

2016-08-18 Thread kpeng
Hello, What's the better way to decide if an element exists in an array? Something like what ruby does, irb(main):001:0> x=[3,1,4,2,9,0] => [3, 1, 4, 2, 9, 0] irb(main):002:0> x.include? 4 => true irb(main):003:0> x.include? 10 => false irb(main):004:0> quit I tried searching but found nothin