tnyflmngs has asked for the wisdom of the Perl Monks concerning the following question:
Hello everyone. Some of you have been kind enough to work with me in chatter with this, but this is a little much to copy in chatter. I am trying to store the file names in an array, which I was surprisingly able to do, however when I try to get each file from the array and open it I am unable to. My suspicion is that I am using the wrong context, my error message is "Couldn't open file: ARRAY", which is why I think I have a list in a scalar context.
sub getFiles { my @fileNames = [ "manimp1.txt", "manimp2.txt" ]; for my $i (0..$#fileNames) { open (FILE, "<", $fileNames[$i]) or die "Couldnt open file: $ +fileNames[$i]\n"; while (<FILE>) { $count++; my @line_array = split (/\t/, $_); chomp(@line_array); my $key = shift(@line_array); my $aref = [@line_array]; $newPrices{$key} = $aref; } delete ($newPrices{'Part Num.'}); } }
I also tried
for my $file (@fileNames) { open (FILE, "<", $file) or die "Couldnt open file: $file\n";
This produced the same error. What I am attempting to do is build one hash with these two files, which was working fine when I was using user input to get the file names but since the file names will not change I wanted to bypass user input.
Sample of the data is as follows:I think I got all of the "problems" in here, double tabs, commas in the prices (who even does that), replacement parts, and non replaced parts.Part Num. Description Base Price Code 001051536 * (R/B 455632) 455632 001460 Ring 11.17 003034 Ball 0.82 018422 Nut 1.69 037506 Ring 3.25 041112023071 Seal Kit 402.98 041112030171 Engine Gasket Kit 611.32 041112030271 Seal Kit 1,035.86
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opening an array of file names
by toolic (Bishop) on Apr 02, 2012 at 18:00 UTC | |
by tnyflmngs (Acolyte) on Apr 04, 2012 at 02:59 UTC | |
|
Re: Opening an array of file names
by ww (Archbishop) on Apr 02, 2012 at 19:46 UTC | |
by tnyflmngs (Acolyte) on Apr 04, 2012 at 03:16 UTC | |
|
Re: Opening an array of file names
by jwkrahn (Abbot) on Apr 02, 2012 at 22:11 UTC | |
by tnyflmngs (Acolyte) on Apr 04, 2012 at 03:08 UTC | |
by jwkrahn (Abbot) on Apr 04, 2012 at 03:36 UTC | |
|
Re: Opening an array of file names
by Marshall (Canon) on Apr 02, 2012 at 18:57 UTC | |
by tnyflmngs (Acolyte) on Apr 04, 2012 at 02:58 UTC |