in reply to Re: Open a directory and recursively process files
in thread Open a directory and recursively process files
Hi blue cowdawg
I tried your sub, but it still does not work. ".:Permission denied at project6.pl line 16." Which is open FIN,"< $fname" or die "$fname:$!"; Any idea why this happens?
#!/usr/bin/perl -w use strict; my $dir = 'C:\Users\Zandre Botha\Desktop\Text Files'; opendir (DIR, $dir) or die "cannot opendir $dir"; foreach my $file (readdir(DIR)) { &process_file ($file); } sub process_file { my $fname=join("/",@_); open FIN,"< $fname" or die "$fname:$!"; my @lines=<FIN>; chomp @lines; close FIN; my $count=0; foreach my $line(@lines) { map { $count++ } split (/[\s\t\n]+/,$line); } printf "There are %d words in %s\n",$count,$fname; } closedir (DIR);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Open a directory and recursively process files
by blue_cowdawg (Monsignor) on Jan 09, 2013 at 20:31 UTC | |
|
Re^3: Open a directory and recursively process files
by Anonymous Monk on Jan 09, 2013 at 20:12 UTC | |
|
Re^3: Open a directory and recursively process files
by marto (Cardinal) on Jan 09, 2013 at 23:30 UTC |