Message-ID: <lrk83eogf6.fsf@caliper.ActiveState.com>
p4raw-id: //depot/perl@10161
{
register I32 count;
STRLEN len;
+ STRLEN n_a;
char *s;
if (RsSNARF(PL_rs))
else if (SvREADONLY(sv))
Perl_croak(aTHX_ PL_no_modify);
s = SvPV(sv, len);
- if (len && !SvPOKp(sv))
- s = SvPV_force(sv, len);
if (s && len) {
s += --len;
if (RsPARA(PL_rs)) {
count += rslen;
}
}
- *s = '\0';
+ s = SvPV_force(sv, n_a);
SvCUR_set(sv, len);
+ *SvEND(sv) = '\0';
SvNIOK_off(sv);
+ SvSETMAGIC(sv);
}
nope:
- SvSETMAGIC(sv);
return count;
}
#!./perl
-print "1..37\n";
+print "1..41\n";
# optimized
my %stuff = (1..4);
print chop(@stuff{1, 3}) eq '4' ? "ok 37\n" : "not ok 37\n";
+
+# chomp should not stringify references unless it decides to modify them
+$_ = [];
+$/ = "\n";
+print chomp() == 0 ? "ok 38\n" : "not ok 38\n";
+print ref($_) eq "ARRAY" ? "ok 39\n" : "not ok 39\n";
+
+$/ = ")"; # the last char of something like "ARRAY(0x80ff6e4)"
+print chomp() == 1 ? "ok 40\n" : "not ok 40\n";
+print !ref($_) ? "ok 41\n" : "not ok 41\n";