Indenting is a wonderful tool for making it much easier to see what is happening in a piece of code. It is a standard practice among folks who want to get a quick visual grasp of the over-all flow of their code. Here is your program with indenting added:
#!/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';
Notice how much more clear the logic of your code becomes when formatted in this way?

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

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.