I can see a continuous pattern in the data you provided

So my guess why don't you generate the ids right away without reading from the first file ?

Something like this might work???

#!/usr/bin/perl -w use strict; my $StartID = ''; my $GenCODE = 'ZZZ'; while (<DATA>) { chomp; my ( $C , $ID , $NO ) = split /\s+/; if ( $ID ne $StartID ) { $StartID = $ID; $GenCODE++; } print "$C $GenCODE $NO\n"; } __DATA__ 3998122 CGP_A0000000001 13 5877245 CGP_A0000000001 17 3637488 CGP_A0000000001 19 3998162 CGP_A0000000001 21 638421 CGP_A0000000001 23 2395226 CGP_A0000000001 25 3094278 CGP_A0000000001 27 2029460 CGP_A0000000001 29 1406937 CGP_A0000000001 31 2054853 CGP_A0000000001 35 4182290 CGP_A0000000001 37 3784069 CGP_A0000000002 13 6477860 CGP_A0000000002 17 394789 CGP_A0000000002 19 5095549 CGP_A0000000002 21 692543 CGP_A0000000002 23 5446227 CGP_A0000000002 25 1546807 CGP_A0000000002 27 1741167 CGP_A0000000002 29 1187972 CGP_A0000000002 31 1600142 CGP_A0000000002 33 1833098 CGP_A0000000002 35 1770403 CGP_A0000000003 1353 3254322 CGP_A0000000003 1355 6152600 CGP_A0000000003 1357 3195476 CGP_A0000000003 1361 3108815 CGP_A0000000003 1371 77684 CGP_A0000000003 1373 3269969 CGP_A0000000003 1375 3259137 CGP_A0000000003 1377 6502805 CGP_A0000000003 1379 5899118 CGP_A0000000003 1381 5417394 CGP_A0000000003 1383 806606 CGP_A0000000003 1385 1662014 CGP_A0000000003 1387 6490426 CGP_A0000000003 1389 6206360 CGP_A0000000003 1391

In reply to Re: Make my script faster and more efficient by ahmad
in thread Make my script faster and more efficient by sesemin

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.