Wow. Thank you Shlomi, Thank you Chas and Thank you Shawn.

Hash sets seem to be the way to go here. Much quickness too!

Here is what I have ( the least I can do is give you all a chance to
laugh
at my code! ):-


#!/usr/bin/perl
use warnings ;

my $names_file = 'C:\names.log' ;
my $exclude_list = 'C:\exclude.txt' ;
my %names_hash ;

open ( NAMES, $names_file ) ;
open ( EXCLUDE, $exclude_list ) ;

@allnames = <NAMES> ;
@allexcludes = <EXCLUDE> ;

#---> Create the hash set #--->
foreach $exclusion ( @allexcludes ) {
        chomp( $exclusion ) ;
        $names_hash{ $exclusion } = 1
}

#---> Walk the names array #--->
foreach $name ( @allnames ) {
        chomp( $name ) ;
        if ( ($dn) = $name =~ /(\d{5,6})/ ) {
                 if ( $names_hash{ $dn } ) {
                     print "This would be excluded: $name\n"
                 } # Close inner IF
         } # Close outer IF
}

This seems to work;  I'm aghast at how quickly it tears through the
data.
My Powershell script was taking 2-3 minutes. This method completes in
about 4 seconds. Though to be fair I'm not using an associative array
in
my Powershell code, so it's not this same.

This is an order of magnitude better than what I am doing now, so big,
big
thanks and I'd be delighted for any pointers for how to make my code
more .. perl'ish.

Thanks,
Stuart


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to