ok, hopefully nobody will shot at me for this huge piece of code, but the following is something we were using for such kind o stuff.
#!/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 $FI +LE_DATA_BASE: $!"; my @keyfields = split(/[;]/, <CURRENT_DB>); ## EXTRACT KEYFIELDS # +# while ($tmp = $keyfields[$i]){ $keyfields{"$name"}{$i} = $tmp; $i++; } my $numofkeys = @keyfields; ## EXTRACT VALUEFIELDS FOR EACH RECORD +SET ## $tmp = $keyfields{"$name"}{($numofkeys-1)}; chomp $tmp; $keyfields{"$name"}{($numofkeys-1)} = $tmp; $i = 0; while ($line = <CURRENT_DB>){ chop $line; my @valuefields = split(/[;]/, $line); if (length($line) != 0){ for ($j = 0; $j < $numofkeys; $j++) { $DATA{"$name"}{($keyfields{$name}{$j})}{$i} = $valuefi +elds[$j]; } } $i++; } close CURRENT_DB; ## END OF READING DATA_BASE ## return $i; } ## ## END OF SUB me_read_CSVDB ## ##############################
so what it does? it is reading the specified files and enables you to access your data by the name of the row in your file.

the files look for now as follows. Play around with that and see for yourself.
But anyway, all suggestions for improvement are very welcome :-)
"../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

have a nice try :-) update: just orthography

In reply to Re: Merging Files Conundrum: A Better Explanation(?) by little
in thread Merging Files Conundrum: A Better Explanation(?) by Limo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.