Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: Open a folder

by blue_cowdawg (Prior)
on Jan 09, 2013 at 14:04 UTC ( #1012492=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Open a folder
in thread Open a folder

      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.

Professor Cowdawg just drew a red "X" across your assignment.

sub countWords { 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; }
You are not counting anything in your sub at all. You actually have to read the file in order to count the words in it.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re^5: Open a folder
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-27 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (232 votes), past polls