On Wed, 25 Sep 2002 12:13:45 +0200
Adriano Allora <[EMAIL PROTECTED]> wrote:
> Hi to all,
> I need a script to open all the files in a directory and count all the
> words of them, but it doesn't work:
>
>
> use Text::ParseWords;
> $folder = "pathname";
> opendir(KART, $folder);
> foreach (readdir(KART)){
> if(grep /\.txt$/, $_){
> $filename = "$_";
> open(INPUT, $filename); ####this one does not work
> while (<INPUT>)
> {
> @words = split;
> $numero = @words;
> }
> print "in the file $filename there are $numero words \n";
> close(INPUT);
> }}
> closedir(KART);
>
> what's the tip I don't know?
> tnx a lot
>
> adr
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
I don't know how accurate this may be:
while (<somedir/*.txt>) {
open FH, $_ or die $!;
while(<FH>) {
local @words = split /\S+/, $_ ;
$total += $#words}
}
}
print "$total\n";
--
vis tecum sit.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]