Notice how much more clear the logic of your code becomes when formatted in this way?#!/usr/bin/perl use strict; use warnings; open FILEB, 'B.txt' or die "B: $!\n"; while (<FILEB>) { my ($id,$add, $expire) = (split /\|/)[5,2,3]; open FILEA, 'A.txt' or die "A: $!\n"; open NEWA, '>A.txt.new' or die "New A: $!\n"; while (<FILEA>) { if (/\|$id\|/) { my @rec = split /\|/; @rec[10, 11] = ($add, $expire): $_ = join ('|', @rec); } print NEWA, $_; } close FILEA; close NEWA: } rename 'A.txt.new', 'A.txt';
Moving on... you do not describe what result you are getting (beyond saying "it is not working").
But as you can see, every time through the while (<FILEB>) loop you are re-writing a new A.txt.new over the top of the one you wrote on the previous time through the loop. Does that shed any light on the unsatisfactory results you are getting?
There are other issues with this code and you may soon see a full re-write of your program posted here. But I suspect this is the main issue at this stage in your work.
UpdateAcidHawk correctly nails several other specific problems. Much of what he calls attention to should have been evident from the error messages produced by your code. Next time, please say more than just "it is not working".
In reply to Re: update flat file
by dvergin
in thread update flat file
by britney
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |