[Israel.pm] Is there an operator like IN in perl

Berler Chanan bc.other at gmail.com
Wed Mar 4 05:17:58 PST 2009


10x
Chanan

PS: I looked for the operator IN :o) in the document, never found it....10x again

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Richie Sevrinsky
Sent: Wednesday, March 04, 2009 3:19 PM
To: Perl in Israel
Subject: Re: [Israel.pm] Is there an operator like IN in perl

Use grep as follows:

my @arr = (1,2,3,4,5);
if (grep($_ == 1, @arr))

I recommend reading "perldoc -f grep".

- Richie



Berler Chanan wrote:
> Hi All,
>
> I wonder why/or should I ask "if" there is an operator IN in perl.
> For example:
>
> my @arr = (1,2,3,4,5);
> if (1 in @arr)
> {
>     # do something
> }
>
> The idea came to me when using SQL statement: select …. where element in (1,2,3,4,5)
> PS: the use of foreach and check is tooooooooo long for me ☺
>
> Thanks
> Chanan
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>   
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list