On 11-08-22 02:25 AM, anant mittal wrote:
Hi!
I want to search whether a scalar '$a' contains any one of value of an array
'@arr'.
How it may be done?
as its not correct : print "found" if $a =~ /@arr/;


First of all, don't use $a or $b as a variable name. `sort` uses them and although `perl` won't get confuse about them, you will.

Try:

#!/usr/bin/env perl

use strict;
use warnings;

use List::Util;

# find first item, undef means nothing found
my $found_item = first { $item =~ m{ \Q$_\E }msx } @list;

__END__

See:
perldoc List::Util
perldoc perlretut
perldoc perlre


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

"Make something worthwhile."  -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to