Hi,
I found this in my "to do" directory (was this from perl.beginners - I don't
remember and can't find it via Google). I tried the "line-range" operator
here, but am wondering if it's possible with it to *not* catch the matching
lines (i.e. only lines "3"-"4"). I suppose if you captured into an array
then you could just shift and unshift. I also tried a second way below not
using range that seems to work well (or?).
-K
# problem:
# This is line1
# some text on line2
# line3 all about me
# good stuff on line4
# line 5 isn't that great
# I'm on line 6
#
# What I want to do is grab the text between 'line 2' and 'line 5'
# grabs lines 2 - 5 inclusive
while (<DATA>) {
print if (/line2/ .. /line 5/);
}
## end
# grabs lines between 2 and 5
my ($on, $off);
while (<DATA>) {
$off++ if /line 5/;
print if $on and not $off;
$on++ if /line2/;
}
__DATA__
This is line1
some text on line2
line3 all about me
good stuff on line4
line 5 isn't that great
I'm on line 6
--
Kevin Pfeiffer
International University Bremen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]