in reply to Efficiency Question

Why not do something like:
foreach (keys %$dirs) { next if $config_dirs->{$skip}; # Do stuff } ---- Or ---- foreach (keys %$dirs) { next if grep {/^$skip/} keys %$config_dirs; # Do stuff }
The second is (as far as I can tell) identical to your code. The first assumes that the entries in $config_dirs is string-wise equal to the entries in $dirs. YMMV

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Efficiency Question
by PrimeLord (Pilgrim) on Mar 21, 2002 at 19:37 UTC
    I'm sorry I forgot to address that. The dirs in %dirs will never exactly match the dirs listed in %config_dirs. The config file will only contain high level directories like /home /etc /usr etc. But the %dirs is going to contain things like /usr/local/bin etc. so an exact match won;t be possible.
      If you're brave, you can construct a regex which you can bang your various directories against. This can be done quite simply like so:
      my $skip = join ('|', map {quotemeta} keys %$config_dirs);
      This will look something like "/usr/bin|/home|/var" or what have you. Now you can just go and check against this, like dragonchild suggested, but with a slight mod:
      foreach (keys %$dirs) { next if /^($skip)/; # Do stuff }
      Presumably if the value of $skip does not change within your program, you can use the /o option to only "compile once" your regular expression.
      But then if you have /home in the config file, you should not print /home/foo? (I did not understand that too well) If you are going to have only high level directories (and by that I mean subdirectories in /), and the directories you have to decide wether or not to print are subdirectories of these high level ones, then I guess you could strip everything after the second '/' and then make a direct comparaison...
      sub print_report { foreach (keys %$dirs) { print BENCHMARK $_; m#^/[^/]+/#; next if defined $config_dirs->{$&}; print "$_\n"; } }
      (I hope I understood the problem correctly)