#!/usr/bin/perl -w use strict; $|++; my (@DBFile, %DATA, $file, $name); $DBFile[0] = "../path/file_A.txt"; $DBFile[1] = "../path/file_B.txt"; my $output = "../path/file_C.txt"; ReadAllData(); print "\n".$DATA{'A'}{'C1'}{0}; print "\n".$DATA{'A'}{'C1'}{1}; print "\n".$DATA{'A'}{'C1'}{2}; print "\n".$DATA{'B'}{'CA'}{0}; print "\n".$DATA{'B'}{'CA'}{1}; print "\n".$DATA{'B'}{'CA'}{2}; ###### ## SUB ReadAllData shall ## read all files specifies in the array @DBFile ## sub ReadAllData { my ( $i, $file); $i = 0; foreach $file (@DBFile) { &me_read_CSVDB($file,$i); $i++; } return $i; } ## ## END SUB ReadAllData ###### ###### ## SUB me_read_CSVDB shall ## READ specified FILE_DATA_BASE ## ## into a large hash ## sub me_read_CSVDB { my ($tmp, $name, $num, $i, $j, $line, %keyfields); $name = $_[0]; $num = $_[1]; my $FILE_DATA_BASE = $name; $name =~ s/(\.txt$)//i; $name =~ s/^\..*?\_//i; $i = 0; $line = ""; open CURRENT_DB, "<$FILE_DATA_BASE" or die "Couldn't open file $FILE_DATA_BASE: $!"; my @keyfields = split(/[;]/, ); ## EXTRACT KEYFIELDS ## while ($tmp = $keyfields[$i]){ $keyfields{"$name"}{$i} = $tmp; $i++; } my $numofkeys = @keyfields; ## EXTRACT VALUEFIELDS FOR EACH RECORDSET ## $tmp = $keyfields{"$name"}{($numofkeys-1)}; chomp $tmp; $keyfields{"$name"}{($numofkeys-1)} = $tmp; $i = 0; while ($line = ){ chop $line; my @valuefields = split(/[;]/, $line); if (length($line) != 0){ for ($j = 0; $j < $numofkeys; $j++) { $DATA{"$name"}{($keyfields{$name}{$j})}{$i} = $valuefields[$j]; } } $i++; } close CURRENT_DB; ## END OF READING DATA_BASE ## return $i; } ## ## END OF SUB me_read_CSVDB ## ############################## #### "../path/file_A.txt" ID;C1;C2;C3;C4 1;one;clown;funny;children 2;two;hero;truly;saga 3;three;monk;honest;perl "../path/file_B.txt" ID;CA;CB;CC;CD 1;one;baby;scream;teddy 2;two;mom;work;book 3;three;daddy;football;PC