I'm attempting to munge together some data from an arbitrary set of files all stored in a single directory. As I have to constantly cross-compare informationi from the data files, iterate through one line of one, but not the others, depending on the results, I thought creating an array of filehandles to later deal with using foreach and while might be a good way to go. However, I'm having some issues dealing with the array of filehandles that (even after reading the wonderful answers here) have made me somewhat puzzled. Namely, for the code:
my @nbdc_filehandles;
my @nbdc_data;
my $index=0;
foreach my $file (@nbdc_files){
open(FILE, "./$nbdc_dir/$file") || die "Can't open ./$nbdc_dir/$fi
+le";
$nbdc_filehandles[$index] = *FILE;
#get the first set of data values
< $nbdc_filehandles[$index] >;
< $nbdc_filehandles[$index] >;
chomp; #get rid of trailing \n
$nbdc_data[$index]=\split(/\t/, $_);
$index++;
}
Which merely opens each file, then iterates to the 2nd line (to get rid of the header), and then chops up the second line of data, I get the error
Use of uninitialized value in scalar chomp at ./temp_merge.pl line 46.
Use of uninitialized value in split at ./temp_merge.pl line 47.
I know it's opening the files properly, as there is not death, and a later usage of the filename is fine, it's just accessing the data. Any thoughts?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.