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
Outer my hash (%...) in perl -ln misbehaves inside a globally-declared function in the script. #14699
Comments
From @shlomifWith this code running under perl -ln: < CODE > use strict; s/\A([0-9]+):\s*//; sub my_func my $x = 1; print join " ", $n, (sort { $a <=> $b } grep { $_ > 1 and $_ <= $root } < / CODE > And with this input: < INPUT > Then I'm getting this output and warnings: < OUTPUT > F=2 F/=2 ; %factors = 2 1 2 F=2 F/=2 ; %factors = 2 1 4 2 F=3 F/=2 ; %factors = 2 1 F/=3 ; %factors = 2 1 6 2 F=5 F/=2 ; %factors = 2 1 F/=5 ; %factors = 2 1 As can be seen %factors inside my_func remains the same throughout the run and https://github.com/shlomif/possible-perl-ln-f-hash-bug I can reproduce this issue with bleadperl as well as with perl-5.20.2 and I hereby disclaim any implicit or explicit ownership on the code and input file, Best regards, Shlomi Fish -- Shlomi Fish http://www.shlomifish.org/ I wear prescription glasses so I may be half-blind, but at least I'm trying Please reply to list if it's a mailing list post - http://shlom.in/reply . |
From @shlomif2: 2 |
From zefram@fysh.orgshlomif@shlomifish.org wrote:
The -n wraps the program in an outer loop. The "my %factors" is You should make the loop explicit. This program is too complex to -zefram |
The RT System itself - Status changed from 'new' to 'open' |
From @shlomifOn Tue May 12 08:19:56 2015, zefram@fysh.org wrote:
I realised all that now and I'm sorry I didn't mention all that in my original post, but the #p5p people on irc.perl.org believed that it should at least warn in this case. Quoting from #p5p : May 11 11:46:08 <rindolf> Hi all. https://github.com/shlomif/possible-perl-ln-f-hash-bug - I can reproduce a problem with the %f lexical/global hash getting nullified here with -ln on bleadperl and perl-5.20.2 built from source on Mageia Linux x86-64 5. Is this a bug? ============ Regards, -- Shlomi Fish |
From @iabynOn Tue, May 12, 2015 at 08:29:39AM -0700, Shlomi Fish via RT wrote:
If I read this all correctly, the complaint is that although this code sub f { this doesn't: while (1) { I think it would be hard in this case to determine at compile time that { -- |
From zefram@fysh.orgDave Mitchell wrote:
What about: { ? -zefram |
From p5p@spam.wizbit.beJust for reference including the code in the pastebins: #!/usr/bin/perl -l use strict; for my $i ("a", "b", "c") { print "Outside sub: " . join(" & ", keys %z); sub s1 { __END__ $ perl x.pl and the other: #!/usr/bin/perl -l use strict; sub s2 { print "Outside sub: " . join(" & ", keys %z); sub s1 { s2(); __END__ Would've expected the bug to get reported with the code of the first pastebin since that clearly shows what is happening and not with the original code... Anyway, my remark was that the warning 'Variable "%z" will not stay shared' would've been nice to see in both cases since that clearly highlights that there was a problem with the code and at least gives a pointer to the issue. |
From @iabynOn Tue, May 12, 2015 at 05:04:01PM +0100, Zefram wrote:
That would again be in the category of "too hard to detect at compile Personally even if we could detect it, I would veer towards not warning -- |
From @epaZefram <zefram <at> fysh.org> writes:
I think this may be another case that argues for distinguishing between So the new syntax 'once { ... }' would be a kind of loop, where 'redo' can be I'm not saying that the above code is necessarily a convincing reason to start -- |
From zefram@fysh.orgEd Avis wrote:
Can't be done without silently changing the language. Even if you detect perl -le 'sub foo { redo unless $z++ } { print ++$i; foo(); }' So the naked block has to remain the do-once loop, and we need some other -zefram |
From @epaAh yes, I always forget that 'redo' and friends are dynamically scoped, so to Personally I consider that something of a misfeature, and I would prefer to -- |
Migrated from rt.perl.org#125162 (status was 'open')
Searchable as RT125162$
The text was updated successfully, but these errors were encountered: