Well, there's no reason to read both files into mem.. you can just process/replace the items in file 2 as you read it..
for example
open(FILE, "<$file1") || die "oh the misery, $!"; while(<FILE>) { chomp; # making the assumption that each field # is delimited by comma space, safe? ($id, $desc) = split(/, /); $update_hash{$id} = $desc; } close(FILE); #create backup rename $file2, "$file2.bak" || die "bah, skum $!"; open(INFILE, "<$file2.bak") || die "dagnabit! $!"; open(OUTFILE, ">$file2") || die "ookiemouth! $!"; while(<INFILE>) { chomp; # once again, assuming data is delimited # by comma space @vals = split(/, /); # update if a new description exists $vals[4] = $update_hash{$vals[2]} if $update_hash{$vals[2]}; # write file delimited by comma space (even last item) foreach $data (@vals) { print OUTFILE "$data, "; } print OUTFILE "\n"; } close(INFILE); close(OUTFILE);
Not a whole lot changed, just some extra stuff, including more validation..
-Syn0

In reply to Re: a hash/array problem and can contents of an array be printed as one line by synapse0
in thread 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.