Your code doesn't look like a real program to me but just as a bunch of editing commands to convert exactly one kind of input to exactly one kind of output. I don't know, whether or not my attempt fits your needs, but try for yourself...
use strict;
use warnings; # use these two always!
my $pattern= qr/^(Line '(\d+)')$/; # This is the line you're searching
+ for
my @holdspace;
while (<DATA>) { #read the input
if (my $hit= /$pattern/o .. not /$pattern/o) {
# this will be executed for every Pattern-line
# and the line after that.
if ($hit==1) {
# If it was the first: Clear the holdspace
@holdspace= ();
}
elsif ($hit=~ /e0/i) {
# If it's the last print everything
print "NewLine1\n",@holdspace,$_;
next;
}
# Store the pattern lines
push @holdspace, "(+$2) $1;fac=$2\n";
next;
}
# Print everything else
print;
}
# That's it
print "MeanLine\n";
__END__
Line1
Line2
Line3
Line '1'
Line '2'
Line '3'
Line4
Line5
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.