Fellow Brothers of Perl, I'm trying to create program that looks in a directory for a file with a specific pattern. If it doesn't find pattern X, it should print the preceding directory name which happens to be a server name. It should only print that server name once, no matter how many files are in the directory. My humble code follows:
my(@node_list) = glob("/appl/perform/workspace/htdocs/node_reports/*/* +"); my($node) = ""; foreach $file (@node_list) { next if($file eq ".") or ($file eq "..") or ($file eq "lost+found" +); (undef,undef,undef,undef,undef,undef,$node,$filename) = split /\// +, $file; my($pattern) = "business_use\.$node"; chomp($node); chomp($filename); unless($filename =~ /^($pattern)/) { %needs_desc = ("$node" => 1); delete $needs_desc{$node} if("$filename" eq "$pattern"); while ( ($key, $value) = each %needs_desc ) { print "$key => $value\n"; } } }
At this point, it will print the $node and "1" for every file in the directory. I had thought it would populate the hash and then remove the $key if the $pattern exists. What I ultimately hope to do is put this is a CSV file with just the $node name. Any guidance you can offer would be appreciated.

In reply to Regex Basics by mbeason

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.