Skip to content

Commit 4a87acf

Browse files
authored
grep: fix -Fh (#635)
* When combining grep -F and -h flags, the filenames were not listed for matches, but they still were not listed when unsetting -h * test1: "perl grep -F '/' awk ar" --> output should show "$filename:" prefix * Init of global variable $Mult was missed due to early return in parse_args() * I also tested that -Fl works as expected * While here, remove the need for variable $optstring by passing options directly to getopts() * Bump version
1 parent 2f29dec commit 4a87acf

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

bin/grep

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,23 @@ EOF
130130
###################################
131131

132132
sub parse_args {
133-
my ( $optstring, $zeros, $nulls, %opt, $pattern, @patterns, $match_code );
133+
my ( $zeros, $nulls, %opt, $pattern, @patterns, $match_code );
134134
my ( $SO, $SE );
135135

136136
if ( defined( $_ = $ENV{'GREP_OPTIONS'} ) ) {
137137
s/^([^\-])/-$1/; # add leading - if missing
138138
unshift @ARGV, $_;
139139
}
140140

141-
$optstring = "incCwsxvhe:f:l1HurtpP:aqTF";
142-
143141
$zeros = 'inCwxvhlut'; # options to init to 0 (prevent warnings)
144142
$nulls = 'epP'; # options to init to "" (prevent warnings)
145143

146144
@opt{ split //, $zeros } = (0) x length($zeros);
147145
@opt{ split //, $nulls } = ('') x length($nulls);
148146

149-
getopts( $optstring, \%opt ) or usage();
147+
getopts('incCwsxvhe:f:l1HurtpP:aqTF', \%opt) or usage();
150148
$opt{'s'} = 1 if $opt{'c'};
149+
$Mult = 1 if ($opt{'r'} || @ARGV > 1 || @ARGV > 0 && -d $ARGV[0]) && !$opt{'h'};
151150

152151
my $no_re = $opt{F} || ( $Me =~ /\bfgrep\b/ );
153152
$match_code = '';
@@ -240,7 +239,6 @@ sub parse_args {
240239
$opt{P} && ( $/ = eval(qq("$opt{P}")) ); # for -P '%%\n'
241240
$opt{w} && ( @patterns = map { '(?:\b|(?!\w))' . $_ . '(?:\b|(?<!\w))' } @patterns );
242241
$opt{'x'} && ( @patterns = map {"^$_\$"} @patterns );
243-
$Mult = 1 if ( $opt{r} || @ARGV > 1 || @ARGV > 0 && -d $ARGV[0] ) && !$opt{h};
244242
$opt{1} += $opt{l}; # that's a one and an ell
245243
$opt{H} += $opt{u};
246244
$opt{c} += $opt{C};

0 commit comments

Comments
 (0)