Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^3: Comparing Values PER Sub-folder

by Kenosis (Priest)
on Sep 05, 2012 at 00:21 UTC ( #991712=note: print w/replies, xml ) Need Help??

in reply to Re^2: Comparing Values PER Sub-folder
in thread Comparing Values PER Sub-folder

Let me first address another issue... Tie::File can be rather slow--especially when used on large files. This is why I used File::Slurp for the line count. Also, remember that you should untie the formerly tied array when done with it.

I ran your subroutine, adding untie @filelines; before the end of the code block, and it executed just fine (it ran fine w/o that addition, too, but it's best to follow a tie with an untie). I'm unsure why you're not getting any output from the routine...

Replies are listed 'Best First'.
Re^4: Comparing Values PER Sub-folder
by omegaweaponZ (Beadle) on Sep 05, 2012 at 00:52 UTC
    Good call about untie. But even if I use slurp I'm still not recieving any print return results.
    find(\&countLines, $dir); sub countLines { /\.txt$/ or return; my $completePath = $File::Find::name; my $curDir = $File::Find::dir; my $curFile = $_; my @lines = read_file( $curFile ) ; my $numLines = @lines; print "Cur dir: $curDir; Cur file: $curFile; Num Lines: $numLines +\n";

    Is this definitely finding every .txt file in ALL sub-directories? I don't understand why it wouldn't even print a current directory or current file unless that .txt parameter is not working and its finding 0 files.

      Yes, provided that the top dir contains *.txt files. You can try commenting out /\.txt$/ or return;, so all files are displayed. Another option is to initialize $dir with the complete path to the 'top' directory you want File::Find to traverse, in case '.' may not be working.

        Looks like I had some type of perl package mis-match. I was attempting to initialize File::Find::Rule on a prior test, which conflicted with something. I re-arranged something also in a different sub and it seems to be working just fine now. I think slurp is a good way to grab this, by setting these to a variable I think a simple comparison of directory to file lines should work well, but I will post again if something else seems to go astray. Thank you for your help!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991712]
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2018-06-24 08:08 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.