SPUG: Array comparison and "breaking" out of a foreach loop
Scott Blachowicz
sab at rresearch.com
Tue Jan 11 17:17:06 CST 2000
On Tue, Jan 11, 2000 at 02:44:19PM -0500, Joel wrote:
> my %seen;
> my @targetArray;
>
> # build lookup table
> @seen{@array2} = ();
>
> foreach $item ( @array1 ) {
> push ( @targetArray, $item ) unless exists $seen{$item};
> }
I wonder if replacing that explicit loop with something like this:
@targetArray = grep {! exists $seen{$_}} @array1;
would be any faster? I don't have the time to play with Benchmark.pm
at the moment...
Scott.Blachowicz at seaslug.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list