in reply to a hash/array problem and can contents of an array be printed as one line
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: a hash/array problem and can contents of an array be printed as one line
by abstracts (Hermit) on Jul 16, 2001 at 03:22 UTC | |
by synapse0 (Pilgrim) on Jul 16, 2001 at 03:34 UTC |