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

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.

Replies are listed 'Best First'.
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?


        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); }


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

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985944]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2017-09-24 04:07 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (273 votes). Check out past polls.