in reply to Re: Efficiency Question
in thread Efficiency Question

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.

Replies are listed 'Best First'.
Re^3: Efficiency Question
by tadman (Prior) on Mar 21, 2002 at 20:33 UTC
    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.
Re: Re: Re: Efficiency Question
by CukiMnstr (Deacon) on Mar 21, 2002 at 21:00 UTC
    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)