Because your data files are very simple, only one hash table is required to hold the industry lookup. I have written a quick and simple code to do what you described. Keep the script simple and straight forward.
use strict; use IO::File; my %industries; # Load the industry definition file my $def = new IO::File "def.txt", "r" or die "Can not open file!"; while (<$def>) { if (m/'(.*?)','(.*?)'/) { $industries{$1} = $2; } } undef $def; # close the file # Load the data file my $dat = new IO::File "dat.txt", "r" or die "Can not open file!"; while (<$dat>) { s/('.*?'),('.*?')/$2,$1/g; # swap the items my $id = substr($_, 1, 2); print "'$id','$industries{$id}'|$_"; } undef $dat;
The input files are -
-- def.txt -- 'BB','Drinks Industry' 'BL','Construction Industry' -- dat.txt -- 'Coffee Suppliers','BB100'|'Tea Suppliers','BB106' 'Plasterers','BL100'|'Fencing Companies','BL102'
And the output is -
'BB','Drinks Industry'|'BB100','Coffee Suppliers'|'BB106','Tea Supplie +rs' 'BL','Construction Industry'|'BL100','Plasterers'|'BL102','Fencing Com +panies'
Cheers. Roger

In reply to Re: Multidimensional array of hashes by Roger
in thread Multidimensional array of hashes by robbiebow

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.