Hello fellow monks. I am not sure if I chose the best title, but its all I could think of. I am wondering if there is a better way to accomplish the task I am working on.

I am working on a script that reads the names of several directories into a hash and then 1) prints the keys to that hash into a benchmark file and 2) prints a report of all the dirs it found. I was later asked to add the ability to read some dir names from a config file and that those names should be skipped in the printed report, but should still be printed into the benchmark file. Here is the solution I came up with. I have stripped the code down to what should be the relevant parts.

use strict; my ($config_dirs) = &read_conf(); my ($dirs) = &search_dirs(); &print(); sub read_conf { my %config_dirs; .... # read the conf file return \%config_dirs; } sub search_dirs { my %dirs; .... # search the dirs return \%dirs; } sub print { foreach (keys %$dirs) { my $no_print = 0; foreach my $skip (keys %$config_dirs) { if (/^$skip/) { $no_print = 1; last; } } print REPORT "$_\n" unless ($no_print == 1); } }


Now that works, but it just seems like there has to be a better way to do that. Any suggestions?

If it helps some examples of what would be in the config file would be things like /home and some of the found dirs would be things like /home/bob and /home/ted. Thanks.

-Prime

In reply to Efficiency Question by PrimeLord

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.