On Sep 25, Adriano Allora said:
>use Text::ParseWords;
Why are you using this module if you're not ACTUALLY using it?
>$folder = "pathname";
>opendir(KART, $folder);
>foreach (readdir(KART)){
> if(grep /\.txt$/, $_){
You probably just want
if (/\.txt$/) { ... }
here. It's simpler. Or you could move the grep() to the for() list:
for (grep /\.txt$/, readdir KART) { ... }
>$filename = "$_";
You don't need to quote a variable by itself...
>open(INPUT, $filename); ####this one does not work
Have you looked at what $filename holds? The readdir() function returns
the NAME of the file. But YOU need "$folder/$_", because you're not IN
the $folder directory.
my $filename = "$folder/$_";
open INPUT, $filename or warn("can't read $filename: $!") and next;
>while (<INPUT>)
>{
>@words = split;
>$numero = @words;
>}
That will only store the number of words in the last line of the file.
my $count = 0;
while (<INPUT>) {
$count++ while /\S+/g;
# or
# $count += () = split;
}
print "File $filename had $count words.\n";
You could also use the file-globbing approach (<dir/*.txt>) as you've been
shown.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]