I was wondering if I could get some input on doing this a better way. I have two files.
File One has data that looks like:

012323444, 4.5 Nuts & Bolts , 234334323, Fuzzy Nut bunnies , 434454554, Pineapple Pops ,
and so on........................

File Two has data that looks like:

3423434444, 45554342365, 012323444, 00000333, description 2 update1, d +ata1, data2 4342344, 46565fg66, 234334323, 00004454, update this, data4, data6 523444234, 466763fg4, 434454554, 00005565, this too update, data7, dat +a8

this is going to be a little hard to explain but here it goes. In file 2 I'm trying to update the descriptions (item 5 on each line) using
the descriptions in file 1. The numbers in column one of file 1 will be used as a key
to match numbers in column 3 of file 2, and then using the description in file1 replace the
the description in file 2 (which is column 5). I thought the best way to do this is:

#open file1, split each line delimited by comma and read into %hash #assume $code, and $description are the key/value pairs of the %hash. #open file2 and read into array while <file2> { my @array2 = <file2>; } #close file2 #open file2 foreach $item (@array2) { @values = split /,/; $values[4] = $hash{$values[2]}; # this should now put the new descrip +tion from the hash print file2 $values[1], ", ", $values[2], ", ", $values[3], ", ", $va +lues[4], ", ", $values[5], ", ", "\n"; # writing the line back into file2 }

I don't know if this is was the cheeziest way to do this. But I'm sure there is a better way to do this
I'm still a newbie to PERL so I don't know if I can do this with a regex.
In a nutshell I begin with file2 read the code on column 3 then match the code in
file 1 and then get the description in file 1 and come back to file2 and update the description
on column 5.

Edit ar0n 2001-07-15 -- Fixed formatting


In reply to a hash/array problem and can contents of an array be printed as one line by shaezi

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.