[Israel.pm] checking for presence of a value in a list

Eli Billauer eli at billauer.co.il
Wed Aug 15 08:30:44 PDT 2007


Short and readable:

@w = (1, 2, 3, 4, 5) ;
print "Found\n" if (grep { $_ == 3 } @w);

    Eli

Amir E. Aharoni wrote:

>my @set = (1, 2, 3, 4, 5);
>foreach (@set) {
>    if (3 == $_) {
>        print "found\n";
>      last;
>    }
>}
>
>  
>


-- 
Web: http://www.billauer.co.il





More information about the Perl mailing list