in reply to boolean IN(); function in perl like

Not built-in. There are probably modules (look for Set::* modules on CPAN) that do it. I just use something like:

sub s_in_a # scalar in array { my $s = shift; foreach (@_) { return 1 if $s eq $_; } 0; }

Replies are listed 'Best First'.
Re^2: boolean IN(); function in perl like
by Frank John (Acolyte) on Jan 14, 2005 at 19:21 UTC
    Thx for the info and code. I can see "my $s =shift;" will take the first parameter passed to sun s_in_a; but I am not clear about @_ in "foreach (@_)", does @_ mean the array you pass in? Is it necessary to pass array by reference then dereferrence it? Thx, I appreciate it.

      Call it something like: s_in_a($scalar, @array_to_check) - no array references here.

      You're correct about @_. From the Perl Predefined Variables page: "Within a subroutine, the array @_ contains the parameters passed to that subroutine."

      /renz.