ad23 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am trying to read multiple files in my perl program. I am using UNIX "ls" command to do the task.
I need to know whether it is the best way to do this to read from following directory structure:
/Data_Files/2010_07_07_15h32m/Data.txt /Data_Files/2010_07_07_16h21m/Data.txt /Data_Files/2010_07_07_16h24m/Data.txt /Data_Files/2010_07_07_18h38m/Data.txt /Data_Files/2010_07_07_19h11m/Data.txt
#!/usr/bin/perl #my @files = ('data1.txt', 'data2.txt', 'data3.txt' ); my @files = `ls Data_files/*/Data.txt`; foreach my $filename(@files){ open FILE, $filename or die "Cannot open $filename for reading: $! +\n"; ### Read Line by Line ### while($line=<FILE>){ #read file line by line } close(FILE); }
Thanks!!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use 'ls' to read files in perl????
by runrig (Abbot) on Jul 07, 2010 at 19:00 UTC | |
|
Re: Use 'ls' to read files in perl????
by FunkyMonk (Bishop) on Jul 07, 2010 at 20:47 UTC | |
by ad23 (Acolyte) on Jul 07, 2010 at 21:08 UTC | |
|
Re: Use 'ls' to read files in perl????
by AndyZaft (Hermit) on Jul 07, 2010 at 19:31 UTC | |
by eyepopslikeamosquito (Archbishop) on Jul 08, 2010 at 08:07 UTC | |
by AndyZaft (Hermit) on Jul 08, 2010 at 13:43 UTC | |
|
Re: Use 'ls' to read files in perl????
by cdarke (Prior) on Jul 08, 2010 at 07:04 UTC | |
|
Re: Use 'ls' to read files in perl????
by perreal (Monk) on Jul 08, 2010 at 08:02 UTC | |
by JavaFan (Canon) on Jul 08, 2010 at 10:06 UTC |