Hi all, I have 2 text files:
1. A.txt 1|||GoRaiders|0473H30DF|123456|Oakland||Test|TD|07/02/2002|01/05/2003| 2|||GoRaiders|019H4151|544419|SpareX||Test|TD|07/02/2002|01/05/2003| 3|||GoRaiders|019H4152|544420|SpareX||Test|TD|07/02/2002|01/05/2003| 4|||GoRaiders||548420|SpareX||Test|TD|07/02/2002|01/05/2003| 5|||GoRaiders||548419|SpareX||Test|Smith|07/02/2002|01/05/2003| 6|||GoRaiders|902F2416|492487|SpareX||Test|TD|08/02/2002|01/20/2003| 7|||GoRaiders|019H4154|544821|SpareX||Test|TD|07/02/2002|01/20/2003| 8|||GoRaiders|924H2CEC|492489|SpareX||Test|TD|07/02/2002|01/20/2003| 2. B.txt 1|TD|01/10/2003|07/11/2003|SpareX|666666||||texas|Yes|Yes|Yes|This is +a test. Please ignore 2|TD|01/10/2003|07/11/2003|SpareX|664464||||newyork|Yes|Yes|Yes|This i +s a test. Please ignore 3|Britney|01/10/2003|07/11/2003|M3|464444|911H3233|||california|Yes|Ye +s|No| 4|TD|01/10/2003|07/11/2003|SpareX|3333333||||texas|Yes|Yes|Yes|This is + a test. Please ignore 5|TD|01/10/2003|07/11/2003|SpareX|4444444||||newyork|Yes|Yes|Yes|This +is a test. Please ignore 6|Britney|01/10/2003|07/11/2003|M3|555555|00000888|||california|Yes|Ye +s|No| 7|TD|01/12/2003|07/11/2003|SpareX|123456||||texas|Yes|Yes|Yes|This is +a test. Please ignore 8|TD|01/12/2003|07/11/2003|SpareX|544419||||newyork|Yes|Yes|Yes|This i +s a test. Please ignore 9|Britney|01/12/2003|07/11/2003|M3|544420|666688855|||california|Yes|Y +es|No|

If today is 01/12/2003 then it will take all the records have today date is 01/12/2003 with expire 07/11/2003 from B.txt with its serial number id, and search in A.txt and check with the serial number in A.txt then replace $addate and $expire.
1|||GoRaiders|0473H30DF|123456|Oakland||Test|TD|01/12/2003|07/11/2003| 2|||GoRaiders|019H4151|544419|SpareX||Test|TD|01/12/2003|07/11/2003| 3|||GoRaiders|019H4152|544420|SpareX||Test|TD|01/12/2003|07/11/2003| 4|||GoRaiders||548420|SpareX||Test|TD|07/02/2002|01/05/2003| 5|||GoRaiders||548419|SpareX||Test|Smith|07/02/2002|01/05/2003| 6|||GoRaiders|902F2416|492487|SpareX||Test|TD|08/02/2002|01/20/2003| 7|||GoRaiders|019H4154|544821|SpareX||Test|TD|07/02/2002|01/20/2003| 8|||GoRaiders|924H2CEC|492489|SpareX||Test|TD|07/02/2002|01/20/2003|

here is my code and it is not working. can you help me to solve it.
#!/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';

Code tags added for data - dvergin 2003-01-12


In reply to 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.