dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is it possible to insert a record after line 5 that appears on line 10?
by Corion (Patriarch) on Jun 23, 2010 at 20:43 UTC | |
Re: Is it possible to insert a record after line 5 that appears on line 10?
by ikegami (Patriarch) on Jun 23, 2010 at 22:03 UTC | |
Re: Is it possible to insert a record after line 5 that appears on line 10?
by bichonfrise74 (Vicar) on Jun 23, 2010 at 20:41 UTC | |
by dirtdog (Monk) on Jun 23, 2010 at 23:00 UTC | |
Re: Is it possible to insert a record after line 5 that appears on line 10?
by AndyZaft (Hermit) on Jun 23, 2010 at 21:47 UTC | |
Re: Is it possible to insert a record after line 5 that appears on line 10?
by kejohm (Hermit) on Jun 23, 2010 at 23:02 UTC |