note
Dr Manhattan
<p>Hi blue cowdawg</p>
<p>I tried this:</p>
<code>#!/usr/bin/perl -w
use strict;
use warnings;
my $dir = 'C:\Users\ZB\Desktop\Text Files';
opendir (DIR, $dir) or die $!;
while (my $file = readdir(DIR))
{
next if $file eq '.';
next if $file eq '..';
&countWords($dir, $file); #call sub
}
sub countWords
{
my $line = @_; #receive file as input
my @array = split(/ /, $line);
print "$#array\n";
}
closedir(DIR);</code>
<p>It is the same thing as earlier, I just added a small sub which is supposed to parse each file into an array, count the words and print the output(total words). Did I call the sub correctly? And does the sub receive the file correctly? When I run the script it gives the same answer(total words) for each text file, which is incorrect.</p>
<p>Thank you</p>
1012201
1012248