-i | --insert-after x Insert after this/matching line.
-f | --insert-before x Insert before this/matching line.
- -R | --regexp-match Use regexp mode for line matching.
- Manipulating block marks:
# Operation defaults
$InsertRemove = DO_INSERT;
$Placement = APPEND_AT_END;
+$RegexpMatch = 1;
$Comment = '#';
$CommentEnd = '';
$MatchLine = '';
$Placement = INSERT_ON_TOP;
}
elsif (/^-R$/ || /^--regexp(?:-match|-mode)?$/) {
- $RegexpMatch = 1;
+ $RegexpMatch = 1; # it's the default
}
elsif (/^-h$/ || /^--help$/) {
die $UsageLong;
}
++ $lineNo;
}
- if (! $added) {
- warn "$ProgramName: Inserting lines at the end implicitly!\n";
+ if ($MatchLine and ! $added) {
+ warn "$ProgramName: Inserting lines at the end implicitly! No '$MatchLine'\n";
push(@Lines, $StdinContent);
}
}
my ($mytrailer, $mybegin, $myend) =
($Trailer, $MarkBegin, $MarkEnd);
+ my ($bm_found, $em_found); # begin/end mark found indicator
+
# Make the strings regexp-friendly by quoting non-word chars.
$mybegin =~ s/\W/\\$&/g;
$myend =~ s/\W/\\$&/g;
foreach (@Lines) {
push (@filtered, $_)
unless (/^$mybegin(?:$mytrailer)?$/o .. /^$myend(?:$mytrailer)?$/o);
+
+ # for safety check:
+ $bm_found = 1 if (/^$mybegin(?:$mytrailer)?$/o);
+ $em_found = 1 if (/^$myend(?:$mytrailer)?$/o);
+ }
+ if ($bm_found and $em_found) {
+ DEBUG and print STDERR "Deleted ". (@Lines - @filtered) ." out of ".scalar(@Lines)." lines\n";
+ @Lines = @filtered;
+ }
+ elsif ($bm_found and ! $em_found) {
+ # safety exit
+ die "$ProgramName: no end-mark after begin-mark!\n";
}
- DEBUG and print STDERR "Deleted ". (@Lines - @filtered) ." out of ".scalar(@Lines)." lines\n";
- @Lines = @filtered;
return scalar(@Lines); # whatever
}