| | |
open 2/more files simultaneously
Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
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???
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???
Perl Syntax (Toggle Plain Text)
opendir (DIR, "path/name of directory") or die "$!"; while(my $file = readdir(DIR)) { next if ($file eq '.' || $file eq '..'); open (my $FH, "path/name of directory/$file") or print "$!\n"; while (my $line = <$FH>) { do something with $line } close $FH; } } closedir DIR;
![]() |
Similar Threads
- Send data on a serial port (C++)
- Vista sucks..not playing any media files (Windows Vista and Windows 7)
- opening two files simultaneously (Visual Basic 4 / 5 / 6)
- Prevent multiple downloads simultaneously (PHP)
- ifstream (C++)
- Browser Battle -- Your TOP Pick! (Geeks' Lounge)
- Ikeep gettin adds! (Viruses, Spyware and other Nasties)
- Opening simultaneously 2 or more apps (Windows NT / 2000 / XP)
- Preparing for an interview and need some questions answered (C)
Other Threads in the Perl Forum
- Previous Thread: Please Suggest
- Next Thread: Handle minimize button in Tk
| Thread Tools | Search this Thread |






