Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Reading Multiple files

by nemesdani (Friar)
on Aug 07, 2012 at 11:47 UTC ( #985944=note: print w/ replies, xml ) Need Help??


in reply to Reading Multiple files

Pack your algorythm in a sub.
Create a list with the names of the files you'd like to process.
Create a loop (a foreach maybe) with which you invoke your sub on every file.


I'm too lazy to be proud of being impatient.


Comment on Re: Reading Multiple files
Download Code
Re^2: Reading Multiple files
by maheshkumar (Sexton) on Aug 07, 2012 at 11:49 UTC

    Like you mean subroutine? But then what about the file names? Will need different file names for each of the file

      You can generate output file names dynamically. For example, my $input=$_[0]; my $output="./Result_of_processing_$input.txt";.
      More strict way: my $output = "Result_".$input.".txt";
      Sorry if my advice was wrong.
Re^2: Reading Multiple files
by bimleshsharma (Beadle) on Aug 07, 2012 at 12:48 UTC
    Here is sample:See if this can help you.
    opendir $dh, $dir_of_files or die "Couldn't open dir '$dir_of_files': +$!"; my @comparefiles= readdir $dh; closedir $dh; for each $file in @comparefiles { read_write_subroutine($file); } sub read_write_subroutine { put your whole code here which is currently you are using }

      Hoe to generate different file names for the output?

        maheshkumar:

        Any way you like. You could do something like:

        my $output_filename="OUTPUT.001"; for my $filename (@filelist) { do_stuff($filename, $output_filename); ++$output; }

        But it would most likely be less confusing to just tack on a new suffix, or squirrel the file away in a different directory:

        for my $filename (@filelist) { my $output_filename = $filename . ".processed"; do_stuff($filename, $output_filename); }

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2014-07-22 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (117 votes), past polls