Setting $/ to a FOO reference is only half forbidden #14245
Comments
From @cpansprout$ ./perl -Ilib -e 'eval {$/={} }; print $@; print ref $/, "\n"' It croaks, but the assignment happens anyway, because the croak is too late. Either this should be a warning, or we should arrange for the previous value of $/ to be preserved. -- Father Chrysostomos |
From @leonerdOn Sat, 15 Nov 2014 16:37:31 -0800
Isn't this just what 'set' magic does though? It can't prevent the Having the 'set' magic store the previous value and restore it on bad -- leonerd@leonerd.org.uk |
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Sun Nov 16 04:47:05 2014, leonerd@leonerd.org.uk wrote:
The valued used by the interpreter is stored in PL_rs, we can just return that in Perl_get_magic(). Tony |
From @tonycoz0001-perl-123218-preserve-if-set-to-a-bad-value.patchFrom a5fe86682f9440cd4c901ab9ee5aa1f49085ea39 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 28 Jan 2015 16:45:21 +1100
Subject: [PATCH] [perl #123218] "preserve" $/ if set to a bad value
and base/rs.t tests $/ not $!
---
mg.c | 1 +
t/base/rs.t | 11 ++++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/mg.c b/mg.c
index 58427a4..237b404 100644
--- a/mg.c
+++ b/mg.c
@@ -1105,6 +1105,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
case ':':
break;
case '/':
+ sv_setsv(sv, PL_rs);
break;
case '[':
sv_setiv(sv, 0);
diff --git a/t/base/rs.t b/t/base/rs.t
index c81b2dc..6f3c4b5 100644
--- a/t/base/rs.t
+++ b/t/base/rs.t
@@ -1,7 +1,7 @@
#!./perl
-# Test $!
+# Test $/
-print "1..38\n";
+print "1..39\n";
$test_count = 1;
$teststring = "1\n12\n123\n1234\n1234\n12345\n\n123456\n1234567\n";
@@ -34,8 +34,13 @@ test_record(*TESTFILE);
close TESTFILE;
$test_count_end = $test_count; # Needed to know how many tests to skip
+$/ = "\n";
+my $note = "\$/ preserved when set to bad value";
+# none of the setting of $/ to bad values should modify its value
test_bad_setting();
-
+print +($/ ne "\n" ? "not " : "") .
+ "ok $test_count # \$/ preserved when set to bad value\n";
+++$test_count;
# Now for the tricky bit--full record reading
if ($^O eq 'VMS') {
--
1.7.10.4
|
From @tonycozOn Tue Jan 27 21:47:01 2015, tonyc wrote:
No objections (or responses of any sort.) Applied as 5fe499a. Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#123218 (status was 'resolved')
Searchable as RT123218$
The text was updated successfully, but these errors were encountered: