Skip to content

Commit a67d122

Browse files
authored
wc: inconsistent byte counts (briandfoy#918)
* The byte count reported by wc was different depending on whether the -w option is set (-w is set by default) * The the code for $opt_w was modifying the line string to calculate a word count before the code for the other options is able to inspect the line * This patch makes the code $opt_w modify its own copy of the line %stat aaa.c File: aaa.c Size: 470 Blocks: 8 IO Block: 4096 regular file Device: b302h/45826d Inode: 1034312 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ pi) Gid: ( 1000/ pi) Access: 2024-11-18 12:56:23.329998345 +0800 Modify: 2024-11-18 12:56:23.329998345 +0800 Change: 2024-11-18 12:56:23.329998345 +0800 Birth: 2024-11-18 12:56:23.329998345 +0800 %perl wc aaa.c 30 66 454 aaa.c %perl wc -c aaa.c 470 aaa.c
1 parent 147df70 commit a67d122

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bin/wc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ sub wc_fh {
169169
}
170170
}
171171
if ($opt{'w'}) {
172-
s/\A\s+//;
173-
@words = split /\s+/;
172+
my $ln = $_;
173+
$ln =~ s/\A\s+//;
174+
@words = split /\s+/, $ln;
174175
$words += scalar @words;
175176
}
176177
if ($opt{'m'}) {

0 commit comments

Comments
 (0)