in reply to Re: Best way to match items in an array
in thread Best way to match items in an array

Another optimization, using eval

my @dlcopy = @dir_list ; my @extensions = qw(zip log whatever) ; my %matches ; foreach my $ext (@extensions) { my $nonmatching = [] ; my $matching = [] ; my $code = q| foreach my $file (@dlcopy) { push @{$file =~ /\\.|.$ext.q|$/ ? $matching : $nonmatching},$file +; } | ; # warn "DEBUG:$code" ; eval $code ; if ($@) { die "Something went wrong: $@" ; } else { @dlcopy = @$nonmatching ; $matches{$ext} = $matching ; } }

This one further optimizes the pattern matching, dynamically creating the inner foreach with the pattern hardcoded (and not reevaluated at each cycle). This could be a great enhancement if you are matching a number of files that is far greater than the number of extensions (since you would have a few evals and a lot of "constant" pattern matchings)

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->make($love) ;
}