kokakola613 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm trying to write a script that parses a file, which itself contains file names. I want to open each one of these files listed and perform some data analysis. However, I'm getting an error any way I try to do it.
Here is my original code (adapted)
open(INP, "<$file_list") or die("Error reading file"); while (<INP>) { my $data_file = m/(\w+)/; # I then call a subroutine which opens the $data_file # and performs some analysis on it }
I wasn't surprised the above didn't work, since INP would have to be closed for the other file to be read in the subroutine I called. However, the following did not work also:
open(INP, "<$file_list") or die("Error reading file"); @lines = <INP>; while (@lines) { my $data_file = m/(\w+)/; # I then call a subroutine which opens the $data_file # and performs some analysis on it }
I then get an error on uninitialized values. I could slurp the entire file into a string, and then use split to get the lines, but that seems like it would be costly. Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiple files opened
by ahmad (Hermit) on Sep 24, 2010 at 05:28 UTC | |
by Anonymous Monk on Sep 24, 2010 at 20:53 UTC | |
|
Re: Multiple files opened
by Anonymous Monk on Sep 24, 2010 at 05:59 UTC | |
by k_manimuthu (Monk) on Sep 24, 2010 at 07:47 UTC | |
|
Re: Multiple files opened
by changma_ha (Sexton) on Sep 24, 2010 at 08:53 UTC |