@@ -133,8 +133,9 @@ BEGIN
133
133
# See if regex has line achor (^ or $)
134
134
# # TODO: exclude \$ at end of string (e.g., "100\$")
135
135
# # TODO: add unit test: (echo "12 34 56 78" | count_it.perl '\d{2}' | wc -l) => 4
136
+ # # TODO2: allow for line archor within grouping parenthesis
136
137
my ($has_line_anchor ) = ((index ($pattern , " ^" ) == 0)
137
- || (rindex ($pattern , " \$ " ) == length ($pattern )));
138
+ || (rindex ($pattern , " \$ " ) == length ($pattern )));
138
139
&init_var(*one_per_line, $has_line_anchor ); # only count one instance of the pattern per line
139
140
&init_var(*multi_per_line, ! $one_per_line ); # count multiple instance of the pattern per line (even when ^ and $ are specified)
140
141
&assertion(! ($one_per_line && $multi_per_line ));
@@ -145,7 +146,10 @@ BEGIN
145
146
eval " use locale;'"
146
147
}
147
148
148
- # Sanity check for whether one-per-line option might be needed
149
+ # Sanity checks for whether -one-per-line option might be needed
150
+ if ((! $one_per_line ) && (! $has_line_anchor ) && ($pattern =~ / [^\] [\^\$ ]/ )) {
151
+ &warning(" Anchors currently start or end line: consider -one_per_line\n " );
152
+ }
149
153
# NOTE: checks against pattern need to occur prior to modification (e.g., paren addition)
150
154
# TODO: handle multiple patterns per line (e.g., set line break to null); likewise check for multiple end-of-line matching
151
155
if ((&DEBUG_LEVEL > 3) && ($pattern =~ / ^\^ / ) && ($pattern !~ / [\$\n ]$ / ) && (! $multi_per_line )) {
0 commit comments