in reply to Opening an array of file names
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.'}); } }
That would probably be better as:
sub getFiles { my @fileNames = ( 'manimp1.txt', 'manimp2.txt' ); for my $file ( @fileNames ) { open my $FILE, '<', $file or die "Couldnt open file: $file be +cause: $!"; while ( <$FILE> ) { chomp; my ( $key, @line_array ) = split /\t/; $newPrices{ $key } = \@line_array; } $count += $.; delete $newPrices{ 'Part Num.' }; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening an array of file names
by tnyflmngs (Acolyte) on Apr 04, 2012 at 03:08 UTC | |
by jwkrahn (Abbot) on Apr 04, 2012 at 03:36 UTC |