[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] find value in array



On Sat, 14 Oct 2000 19:03:35 -0800, g3pb wrote:

>is there a way other then using foreach to determie if an array contains a
>particular value. in AppleScript it would be
>
>if list contains value then
>    -- do stuff
>end if

grep(), or, if you need this test a lot, you should populate a hash.

	if(grep { $_ eq $item } @list) {
	    print "List contains $item!\n";
	}

	@hash{@list} = ();
	if(exists $hash{$item}) {
	    print "List contains $item!\n";
	}

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org