The original cause of the problem was not so much with "find", but rather with `cat $html_dir/$good_file` -- when running a shell command this way, cat will always tokenize the shell will always tokenize the output from cat (or other backtick command) on any whitespace, treating all whitespace the same (yielding a separate argument string) without paying any attention to any sort of escape mechanism (quotes, backslash, etc).

I don't want to discourage you from figuring out the proper way to use File::Find, but in my own experience, this module has normally been significantly slower in any task when compared to the standard "find" shell utility (and let's face it, File::Find's usage has a strange, counter-intuitive feel to it, which has tripped up a lot of folks).

Given your situation, that suddenly the list in "$html_dir/$good_file" happens to contain items with internal spaces, I would be inclined to figure out how to keep using the shell "find" approach -- e.g.:

open (LIST, "<$html_dir/$good_file"); my @paths = <LIST>; close LIST; chomp @paths; my $total = 0; for my $p (@paths) { my $count = qx/find "$p" -type d -name class | wc -l/; chomp $count; $total += $count; }
Being able to put double quotes around the path argument in the find command line makes all the difference.

You might think you spend a lot of overhead running this many subshells with "qx//", but I wouldn't be surprised if this still ends up running faster than the equivalent File::Find solution (once you get that working -- good luck with that).

update: added "$total" to the code sample.


In reply to Re: Problems using File::Find by graff
in thread Problems using File::Find by thewalledcity

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.