Not a whole lot changed, just some extra stuff, including more validation..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);
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |