open 2/more files simultaneously

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2008
Posts: 5
Reputation: perltoday is an unknown quantity at this point 
Solved Threads: 0
perltoday perltoday is offline Offline
Newbie Poster

open 2/more files simultaneously

 
0
  #1
Oct 2nd, 2008
hi,

Is it possible to read 2 or more files and getting data out of them simultaneously? can I know the perl format for that
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: open 2/more files simultaneously

 
0
  #2
Oct 2nd, 2008
Sure,
open F1,...
open F2,...

then
aLine = <F1>
anotherLine=<F2>

and so on
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 5
Reputation: perltoday is an unknown quantity at this point 
Solved Threads: 0
perltoday perltoday is offline Offline
Newbie Poster

Re: open 2/more files simultaneously

 
0
  #3
Oct 2nd, 2008
sorry,

What i meant was to open more than 2 files.. say 1000 files within a while loop and then retrieve some data from those files one at a time...for example to open a directory with 1000 files and then read those files one at a time....

is this possible? wat is the syntax for this kind of a problem
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: open 2/more files simultaneously

 
0
  #4
Oct 2nd, 2008
Open each one of them in turn?
Or open many of them at once?
- Because there are limits to how many files you can have open at the same time

If you list the files on the command line, then
while ( <> )
will process each file in turn
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 5
Reputation: perltoday is an unknown quantity at this point 
Solved Threads: 0
perltoday perltoday is offline Offline
Newbie Poster

Re: open 2/more files simultaneously

 
0
  #5
Oct 4th, 2008
Yes, I meant each file in turn.
For ex: if a directory has 100 or more files, then u write the syntax:

open (DIR, "path/name of directory");


then you read the directory within a while loop and read each file.
I would like to know how to open one file at a time,read them, do something with that file and create an output file within the program itself. is this possible. I dnt know the syntax for this, where in within the while loop after each file, it automatically prints the output to an output file, so as and when a file is read, it conducts a process and prints the output to an output file. this iteration shud take place for probably 1000 files in a directory. is this possible?... syntax???
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: open 2/more files simultaneously

 
0
  #6
Oct 5th, 2008
  1. opendir (DIR, "path/name of directory") or die "$!";
  2. while(my $file = readdir(DIR)) {
  3. next if ($file eq '.' || $file eq '..');
  4. open (my $FH, "path/name of directory/$file") or print "$!\n";
  5. while (my $line = <$FH>) {
  6. do something with $line
  7. }
  8. close $FH;
  9. }
  10. }
  11. closedir DIR;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC