New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug when using 4-param substr as an argument to a function #1004
Comments
From jbodwin@sebringring.comThanks. - Jim =============================================== sub foo { my ($str) = "abcdefghijklmnopqrstuvwxyz"; my ($ucafew) = foo(substr($str, 0, 4, "xxxx")); print "$ucafew $str\n"; my ($notuc) = substr($str, 0, 4, "yyyy"); print "$notuc $str\n"; ============================================
|
From @gsarOn Wed, 29 Dec 1999 17:21:45 PST, Jim Bodwin wrote:
Here's a fix. Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4747 by gsar@auger on 2000/01/02 20:17:36
fix 4-arg substr() when used as argument to subroutine
Affected files ...
... //depot/perl/pp.c#166 edit
... //depot/perl/t/op/substr.t#12 edit
Differences ...
==== //depot/perl/pp.c#166 (text) ====
Index: perl/pp.c
--- perl/pp.c.~1~ Wed Jan 5 10:44:22 2000
+++ perl/pp.c Wed Jan 5 10:44:22 2000
@@ -2021,7 +2021,9 @@
sv_pos_u2b(sv, &pos, &rem);
tmps += pos;
sv_setpvn(TARG, tmps, rem);
- if (lvalue) { /* it's an lvalue! */
+ if (repl)
+ sv_insert(sv, pos, rem, repl, repl_len);
+ else if (lvalue) { /* it's an lvalue! */
if (!SvGMAGICAL(sv)) {
if (SvROK(sv)) {
STRLEN n_a;
@@ -2050,8 +2052,6 @@
LvTARGOFF(TARG) = pos;
LvTARGLEN(TARG) = rem;
}
- else if (repl)
- sv_insert(sv, pos, rem, repl, repl_len);
}
SPAGAIN;
PUSHs(TARG); /* avoid SvSETMAGIC here */
==== //depot/perl/t/op/substr.t#12 (xtext) ====
Index: perl/t/op/substr.t
--- perl/t/op/substr.t.~1~ Wed Jan 5 10:44:22 2000
+++ perl/t/op/substr.t Wed Jan 5 10:44:22 2000
@@ -1,6 +1,6 @@
#!./perl
-print "1..106\n";
+print "1..108\n";
#P = start of string Q = start of substr R = end of substr S = end of string
@@ -209,3 +209,9 @@
eval 'substr($a,0,0,"") = "abc"';
print "not " unless $@ && $@ =~ /Can't modify substr/ && $a eq "foo";
print "ok 106\n";
+
+$a = "abcdefgh";
+print "not " unless sub { shift }->(substr($a, 0, 4, "xxxx")) eq 'abcd';
+print "ok 107\n";
+print "not " unless $a eq 'xxxxefgh';
+print "ok 108\n";
End of Patch. |
Migrated from rt.perl.org#1954 (status was 'resolved')
Searchable as RT1954$
The text was updated successfully, but these errors were encountered: