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
$& magic can get fetched too late #11406
Comments
From @ntyniThis is a bug report for perl from Niko Tyni <ntyni@debian.org>, In some circumstances $& magic gets fetched too late so that ./perl -e '$_="not ok"; for my Evaluating the variable right away (with stringification for instance) ./perl -e '$_="not ok"; for my I don't have a fix, but there's a TODO test in the attached patch. Originally reported by Ian Jackson in http://bugs.debian.org/627613 Flags: Site configuration information for perl 5.15.0: Configured by niko at Thu Jun 2 23:07:45 EEST 2011. Summary of my perl5 (revision 5 version 15 subversion 0) configuration: Locally applied patches: @INC for perl 5.15.0: Environment for perl 5.15.0: |
From @ntyni0001-TODO-test-for-delayed-evaluation-of.patchFrom 50aaee3ad389646fa1df64fb158450a116e26d79 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Fri, 3 Jun 2011 09:02:30 +0300
Subject: [PATCH] TODO test for delayed evaluation of $&
In some circumstances $& magic gets fetched too late so that
another match has already overwritten the value.
./perl -e '$_="not ok"; for my $m ( (/ok/ and $&), /$_/) { print $m, "\n"; last }'
not ok
Evaluating the variable right away (with stringification for instance)
makes the bug go away.
./perl -e '$_="not ok"; for my $m ( (/ok/ and "$&"), /$_/) { print $m, "\n"; last }'
ok
Add a TODO test for this.
Originally reported by Ian Jackson in http://bugs.debian.org/627613 .
---
t/re/pat.t | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/t/re/pat.t b/t/re/pat.t
index 4ef9663..b778a9d 100644
--- a/t/re/pat.t
+++ b/t/re/pat.t
@@ -21,7 +21,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 451; # Update this when adding/deleting tests.
+plan tests => 454; # Update this when adding/deleting tests.
run_tests() unless caller;
@@ -1167,6 +1167,23 @@ sub run_tests {
is($got,$want,'RT #84294: check that "ab" =~ /((\w+)(?{ push @got, $2 })){2}/ leaves @got in the correct state');
}
+ {
+ local $_ = '12';
+
+ for my $m ( (/1/ ? 0+$& : '3'), /2/) {
+ is($m, 1, 'numified $& comes from the right match'); last;
+ }
+ for my $m ( (/1/ ? "$&" : '3'), /2/) {
+ is($m, 1, 'stringified $& comes from the right match'); last;
+ };
+ TODO: {
+ local $::TODO = '$& get magic handled too late?';
+ for my $m ( (/1/ ? $& : '3'), /2/) {
+ is($m, 1, 'plain $& comes from the right match'); last;
+ }
+ }
+ }
+
} # End of sub run_tests
1;
--
1.7.5.3
|
From @LeontOn Fri, Jun 3, 2011 at 8:14 AM, Niko Tyni <perlbug-followup@perl.org> wrote:
For doesn't read (or write) a variable, it aliases it; therefore Leon |
The RT System itself - Status changed from 'new' to 'open' |
From @ntyniOn Fri, Jun 03, 2011 at 12:35:00PM +0200, Leon Timmermans wrote:
I may have refined the test case too much, sorry about that. The original one didn't have a for loop: my $thing = "1-word"; This gives "word" instead of the expected "1". Is hash population also a case where the values should not be actually read? |
From @ikegamiOn Fri, Jun 3, 2011 at 2:14 AM, Niko Tyni <perlbug-followup@perl.org> wrote:
C<for> aliases, so C<$m> is an alias to C<$&>, so C<print $m> is the same as |
@ikegami - Status changed from 'open' to 'rejected' |
From @ikegami
Assigning $& to something requires reading it and therefore a magic |
From ebhanssen@cpan.orgOn Fri, Jun 3, 2011 at 6:38 PM, Eric Brine via RT <perlbug-followup@perl.org
Right. The list is built (by the comma and fat comma operators) before sidhekin@bluebird[18:40:43] As a simplification, you could say that the comma operators, as we well Eirik, oh, right, simplification? hang on ... |
From @ikegamiDon't read a variable in the same expression in which it changes. On Fri, Jun 3, 2011 at 12:38 PM, Eric Brine via RT <
As a guideline, don't read a variable in the same expression in which it |
From @iabynOn Fri, Jun 03, 2011 at 09:38:51AM -0700, Eric Brine via RT wrote:
Indeed. It's really not much different from @a = (++$i, ++$i, ++$i, ++$i); print "@a\n"; which prints "4 4 4 4", not "1 2 3 4". I think this is NOTABUG. -- |
Migrated from rt.perl.org#92164 (status was 'rejected')
Searchable as RT92164$
The text was updated successfully, but these errors were encountered: