Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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?


        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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2015-03-29 20:21 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (632 votes), past polls