Oh ye Wise one's

I'm trying to figure out a way to loop thru a file looking for a record that begins with :35B: but only if it comes after(does not have to be immediately after) a :16R:SECMOVE record. Once found, i have to copy the :35B: record just under the above and nearest :17B: record which i've already passed.

#!/usr/bin/env perl use warnings; use strict; use Data::Dumper; my @B_Record; my $Rflag=0; my $Bflag=0; my $line; while (<DATA>) { if ( /^:17B:/) { print; $line = $.; print "35B to be copied after this line: $line\n"; next; } if ( (/^:16R::SECMOVE/) && ($Rflag == 0) ) { print; $Rflag = 1; next; } if ( ( /^:35B:/) && ($Rflag == 1) ) { print; splice(@B_Record); push @B_Record, $_; $Rflag = 0; $Bflag = 1; next; } if ( $Bflag == 1 ) { print; push @B_Record, $_; $Bflag = 0; next; } print; } __DATA__ :16S:LINK :16S:GENL :16R:USECU :35B:/GB/B5SDC53 UNICREDIT SP RIGHTS :16R:FIA :12C::CLAS//RXXXXX :16S:FIA :16R:ACCTINFO :97A::SAFE//NONREF :16S:ACCTINFO :16S:USECU :16R:CADETL :98A::RDTE//20100113 :16S:CADETL :16R:CAOPTN :13A::CAON//001 :22F::CAOP//EXER :17B::DFLT//N :98A::EXPI//20100129 :69A::PWAL//20100111/20100129 :16R:SECMOVE :22H::CRDB//CRED :35B:/GB/1234567 UNICREDIT SPA EUR0.50 :69A::TRDP//20100111/20100122 :90B::PRPP//ACTU/EUR1,589 :92D::NWRT//3,/20, :98B::PAYD//UKWN :16S:SECMOVE :70E::ADTX//PAYOUT METHOD TYPE CODE:SR NEW SHARE TYPE CODE:C TAXABLE CODE:N :16S:CAOPTN :16R:ADDINFO :70E::ADTX//CORP ACTION TYPE:SUBOFF

The above code is what i have so far...i just can't figure out how i'm going to print out a record after line 5 that I captured from line 10! hypothetically speaking

Any help would be mucho appreciated

Thanks


In reply to Is it possible to insert a record after line 5 that appears on line 10? by dirtdog

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.