Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Input Output Question

by vinoth.ree (Monsignor)
on Jul 15, 2013 at 04:52 UTC ( #1044268=note: print w/replies, xml ) Need Help??


in reply to Input Output Question

To read all the files in a directory use the directory functions: opendir(), closedir() and readdir().

opendir DIR, $dir or die "cannot open dir $dir: $!"; my @file= readdir + DIR; closedir DIR;
@file array will contains the files available in input directory parse each file and redirect output to output directory with the same file name.


All is well

Replies are listed 'Best First'.
Re^2: Input Output Question
by perlmonk007 (Novice) on Jul 15, 2013 at 04:56 UTC

    thanks, how do I output the files one by one? could you please give me an example?

      Simply use the foreach loop to parse each file and redirect the output to output directory

      For Example:
      my $output_dir = 'output/'; foreach my $file (@files) { print $file . "\n"; #Parse the file here open(FH, '>>', $output_dir.$file ) or die "Unable to open the +file: $!"; print FH "Output goes into output directory with the same file + name\n"; close(FH); }

      All is well

        I tried it that way, it doesnt work, The three folders code, input and output are in the same level in the directory structure (The folders are in a single folder ) and I need to output the result of the pipeline into the output folder with the names unchanged. sadly the code you provided is not working.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044268]
help
Chatterbox?
[Discipulus]: hdb sorry i profit; is known that a prime number is never a figurate one nor the sumattion of two adjacent figurates of the same order? like 3th triangular+3th tetrahedric
[Discipulus]: if known where i can read about the matter?
[choroba]: he's not really sick, we just got nobody to look after him today
[Discipulus]: create an account for him; we are funny baby sitters ;=) come here child, want to listen the typeglob tale?
[vrk]: choroba Oh, that's good.
[vrk]: Discipulus I don't know much about prime numbers, but wouldn't that kind of an answer be in a graduate-level number theory book?
[Discipulus]: my 8 yo daughter has two weeks of sleep disturbs.. we are gonna be crazy..

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-04-27 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (501 votes). Check out past polls.