in reply to Re^3: Open a folder
in thread Open a folder
Hi blue cowdawg
I tried this:
#!/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);
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.
Thank you
In Section
Seekers of Perl Wisdom