bob@dhw68k.cts.com (Bob Best) (07/28/88)
Although, by a fluke, the cut.pl posting runs without error, there is
a bug of mine involving usage of the incorrect type of equality test.
The line:
if ($i == '-') { #range
should read:
if ($i eq '-') { #range
In the upper line, perl evaluates '-' to numeric zero.
The following patch will fix this, as well as fix the -s (suppress) option
to suppress blank lines.
I strongly encourage perl programmers to distinguish the two varieties
(string and numeric) of equality test to avoid this potentially serious pitfall.
Index: cut.pl
*** cut.pl~
--- cut.pl
**************
*** 97,103
if ($clist) {
$j=1;
foreach $i (@list) {
! if ($i == '-') { #range
$ptr=$offsets[$j];
$cnt=$lengths[$j++];
$printlist .= "substr(\$_,$ptr,$cnt), ";
--- 97,103 -----
if ($clist) {
$j=1;
foreach $i (@list) {
! if ($i eq '-') { #range
$ptr=$offsets[$j];
$cnt=$lengths[$j++];
$printlist .= "substr(\$_,$ptr,$cnt), ";
**************
*** 116,122
line: while (<>) {
chop;
\$maxfld = $split;
! ${print}next line if \$maxfld == 1;
$toend
$printlist
}
--- 116,122 -----
line: while (<>) {
chop;
\$maxfld = $split;
! ${print}next line if \$maxfld <= 1;
$toend
$printlist
}
--
Bob Best
uucp: ...{trwrb,hplabs}!felix!dhw68k!bob InterNet: bob@dhw68k.cts.com