I
it_says_BALLS_on_your forehead
i was looking in the Cookbook (2nd ed. pg. 199), and tried to extract a
range of lines using the examples given. one uses '..' (inclusive) and
the other uses '...' (exclusive...supposedly).
it appears that they both do the same thing however. for 3dot, i expect
lines between the patterns. for 2dot, i expect lines between and
including the patterns. i get lines between and including for both
however. can anyone explain this? or am i misinterpreting something?
here is the code:
use strict; use warnings;
my $file = 'data/regex_ranges.txt';
open my $fh, '<', $file or die "can't open $file: $!\n";
while ( <$fh> ) {
chomp;
if ( /START/ ... /END/ ) {
print "3dot: >>$_<<\n";
}
}
close $fh;
print "\n", '-' x 40, "\n";
open my $fh2, '<', $file or die "can't open $file: $!\n";
while ( <$fh2> ) {
chomp;
if ( /START/ .. /END/ ) {
print "2dot: >>$_<<\n";
}
}
close $fh2;
# i used files, b/c with __DATA__ the first while used it up, but the
file contains
# the same thing as __DATA__
__DATA__
START test
first name=Homer
middle name=Jay
last name=Simpson
END test
START test
first name=Bart
middle name=
last name=Simpson
END test
START test
first name=Lisa
last name=Simpson
END test
range of lines using the examples given. one uses '..' (inclusive) and
the other uses '...' (exclusive...supposedly).
it appears that they both do the same thing however. for 3dot, i expect
lines between the patterns. for 2dot, i expect lines between and
including the patterns. i get lines between and including for both
however. can anyone explain this? or am i misinterpreting something?
here is the code:
use strict; use warnings;
my $file = 'data/regex_ranges.txt';
open my $fh, '<', $file or die "can't open $file: $!\n";
while ( <$fh> ) {
chomp;
if ( /START/ ... /END/ ) {
print "3dot: >>$_<<\n";
}
}
close $fh;
print "\n", '-' x 40, "\n";
open my $fh2, '<', $file or die "can't open $file: $!\n";
while ( <$fh2> ) {
chomp;
if ( /START/ .. /END/ ) {
print "2dot: >>$_<<\n";
}
}
close $fh2;
# i used files, b/c with __DATA__ the first while used it up, but the
file contains
# the same thing as __DATA__
__DATA__
START test
first name=Homer
middle name=Jay
last name=Simpson
END test
START test
first name=Bart
middle name=
last name=Simpson
END test
START test
first name=Lisa
last name=Simpson
END test