At 12:28 PM 6/27/02 -0400, Nikola Janceski wrote: >## this is a structure that contains the exceptions >our %except = ( > "test1" => [ "stuff to add" ], > "test2" => [ "more stuff to add" ] > # etc. for about 4 or 5 more > ); > >## [snip to later in the code to some subroutine working] > >FILE: foreach my $file ( @arrayOfManyManyFiles ){ > > ## deal with exception first which doesn't occur often > ## this is the slow solution but I need to use the keys of %except >as a regex > foreach my $test (keys %except) { > if($file =~ /$test/){ > # do stuff with @{ $except{$test} } > next FILE; > } > } > > ### does work to other files that weren't an exception >} > >__END__ > >Any ideas on how to work around recompiling /$test/ every time? AND >to get around going through the foreach my $test so many useless times?
How do you know this is the bottleneck? Have you profiled it with something like Devel::SmallProf? You could perhaps form a single regex from all the keys of %except, but I think I'd need to know what sort of regexen those keys are. Are they in fact literal strings like you have shown, "test1" etc, or do they contain regex metacharacters? You could build a subroutine that does exactly the regex tests you want; Joe Hall shows how to do this in "Effective Perl Programming" (Addison-Wesley). But before we go there, some profiling would appear to be in order. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]