Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 ( #846170=note: print w/replies, xml ) Need Help??


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

Here's something to help you get started. Notice in the first pass, I grabbed the 3rd record. And in the second pass, I printed the 2nd record.
#!/usr/bin/perl use strict; my $data_pos = tell DATA; my $record; while (my $line = <DATA>) { chomp( $line ); $record = $line if ( $line =~ /^:16R:USECU/ ); } seek DATA, $data_pos, 0; while (my $line = <DATA>) { chomp( $line ); print "$line\n" if ( $record && $line =~/^:16S:GENL/ ); } __DATA__ :16S:LINK :16S:GENL :16R:USECU
  • Comment on Re: Is it possible to insert a record after line 5 that appears on line 10?
  • Download Code

Replies are listed 'Best First'.
Re^2: Is it possible to insert a record after line 5 that appears on line 10?
by dirtdog (Scribe) on Jun 23, 2010 at 23:00 UTC

    Thanks for all the advice and input! it looks like i will definitely have to loop thru the file twice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://846170]
help
Chatterbox?
[LanX]: fun, last time I was in Britain people had problems with my name, just rarely they said "like the children TV star Rolf Harris?", this time most replied instantly "Rolf? like the pedophile Rolf Harris" ?
LanX is perlophile
[ambrus]: Corion: read https://metacpan. org/pod/release/ MLEHMANN/AnyEvent- 7.13/lib/AnyEvent. pm#SUPPLYING-YOUR- OWN-EVENT-MODEL- INTERFACE in that case

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2016-12-08 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (140 votes). Check out past polls.