Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: Regex and writing lines in file

by BillKSmith (Chaplain)
on May 01, 2013 at 18:45 UTC ( #1031630=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Regex and writing lines in file
in thread Regex and writing lines in file

The following code uses an array as a "circular list" to delay the printing of the EXTRA. Is this what you need?

use strict; use warnings; my $match = qr /Match/; my $extra = qq(EXTRA\nEXTRA\n); my @extras = (q()) x 3; my $in = 3; my $out = 0; while (my $line = <DATA>) { $out = ($out+1) % 4; print $line, $extras[$out]; $in = ($in +1) % 4; $extras[$in] = ($line =~ /$match/)? $extra : q(); } __DATA__ a b Match1 Match2 c d e f g Match3 h i j k
Bill


Comment on Re^3: Regex and writing lines in file
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-12-26 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls