Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How can a user specify a input folder

by PerlVader (Initiate)
on Dec 10, 2012 at 08:12 UTC ( #1008072=perlquestion: print w/ replies, xml ) Need Help??
PerlVader has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks

I have a small perl script with a hash (frequency list of words of some text file which I can specify) and a array (list of English words). The script checks how many words of the input text file matches words in the array and then scores a percentage depending on how many words matched out of the total.

I have a folder with about a hundred text files that I want to run the same script on. I want to code my perl script to ask the user to type in the folder name, and then the script should run through all of the text files within. How can I do this?

Also, once the script has run through all of the text files I want to output them into different folders depending on the percentage they scored. For example if a text file matches 75 percent, I want the perl script to place it into a folder named '75'. How can I do this?

Comment on How can a user specify a input folder
Re: How can a user specify a input folder
by marquezc329 (Scribe) on Dec 10, 2012 at 08:24 UTC

    Hello PerlVader,

    The answers to your "How can I do this"'s can all be found in Perlintro. You should also take a look at How (Not) To Ask A Question. Show us what you've tried, and where you run into trouble. This sounds like a homework question, so you're unlikely to find much help here without showing some effort.

Re: How can a user specify a input folder
by moritz (Cardinal) on Dec 10, 2012 at 09:18 UTC
    I want to code my perl script to ask the user to type in the folder name, and then the script should run through all of the text files within.

    Let me propose another way: let the user supply the value at the command line. That's much more convenient to use and test. You can find the command line arguments in @ARGV.

Re: How can a user specify a input folder
by CountZero (Bishop) on Dec 10, 2012 at 10:43 UTC
    File::Find::Rule's start and match methods can be used to iterate over all files in a directory or list of directories. Within the while loop you can then process each file found.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (19)
As of 2014-11-26 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls