-
Notifications
You must be signed in to change notification settings - Fork 577
Undef evaluated to array in some conditions #12758
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
Comments
From [email protected]Created by [email protected]<code> use strict; my $errors = undef; sub ok ok( ($errors && ($errors->[0] =~ /Journal file not found/i)), "some prints the following: <code> and by the way this code (with modified 'some text' strings) use strict; my $errors = undef; sub ok ok( ($errors && ($errors->[0] =~ /Journal file not found/i)), "some text 1" ); prints correct result: <code> perl 5.10.1 under Linux p.s. Perl Info
|
From [email protected]This was autovivification, I didn't realized that it happens on On Wed Feb 06 03:52:03 2013, vsespb wrote:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
|
[email protected] - Status changed from 'new' to 'rejected' |
From @demerphqOn 6 February 2013 13:01, Victor Efimov via RT
Note also that your code ends up returning an empty list in some cases Yves -- |
From [email protected]Ok, 1st issue - autovivification that two issues not a bug in perl, but bugs in code. but what about this: #!/usr/bin/perl use strict; my $errors = undef; sub ok $errors->[0]; prints [[[some text ]]] [[[]]] and #!/usr/bin/perl use strict; my $errors = undef; sub ok ok(($errors && ($errors->[0] =~ /Journal file not found/i)), "some text prints [[[ARRAY(0xa89d48)]]] [[[some text ]]] how come first argument become an array ? First argument should be TRUE On Wed Feb 06 04:05:40 2013, demerphq wrote:
|
[email protected] - Status changed from 'rejected' to 'new' |
From @demerphqOn 6 February 2013 13:23, Victor Efimov via RT
Part of it is left to right evaluation of the arguments to ok(). If $errors is false, then the && operator returns the value of $errors If $errors is true then the && operator returns the value returned by What you seem to be missing is that the match is done in _list_ context. If you changed the expression to: ok(($errors && (scalar $errors->[0] =~ /Journal file not found/i)), You would get the behavior you expect. Similarly if you changed the sub ok( Which is the prototype that Test::More::ok() uses then you would not cheers, -- |
The RT System itself - Status changed from 'new' to 'open' |
From [email protected]#!/usr/bin/perl use strict; my $errors = undef; sub ok( still prints On Wed Feb 06 04:46:11 2013, demerphq wrote:
|
From [email protected]Seems people found solution http://www.perlmonks.org/?node_id=1017413 On Wed Feb 06 04:54:07 2013, vsespb wrote:
|
From [email protected]shortest PoC is perl -e 'sub a($$) { print "[$_]\n" for @_}; my $x = undef; a($x && perl -e 'sub a($$) { print "[$_]\n" for @_}; my $x = undef; $x=[]; a($x I don't know guys, if this intended behaviour or no, or maybe not however, for example in Ruby ruby -e 'def a(i,j); puts "Z #{i} Z #{j} Z"; end; x=nil; a(x && x[0] =~ ruby -e 'def a(i,j); puts "Z #{i} Z #{j} Z"; end; x=nil; x=[]; a(x && both print Z Z [] Z On Wed Feb 06 06:59:44 2013, vsespb wrote:
|
From @demerphqOn 6 February 2013 13:54, Victor Efimov via RT
AH, interesting, so the $errors->[0] in the string autovivifies But you seem to have missed the point with scalar/( The use of scalar and ( Take a look at this output use strict; sub ok { sub ok_proto( for my $val (undef, []) { $errors= $val; $errors= $val; $errors= $val; } -- |
From @demerphqOn 6 February 2013 16:45, Victor Efimov via RT
This is absolutely expected behavior and is exactly what I was trying I dont know if ruby has such a thing as context, I suspect not, so You probably should also read up on autovivification. And you should probably read up on prototypes. And you should read up on the aliasing of arguments to perl. And, IMO you should refrain from filing any perl bugs until you have To be honest you are already in the "long grass" here, and probably Yves -- |
From [email protected]2demerphq, This I understood 1) subroutine arguments (without proto) are eveluated in list context but my last message NOT related to autovivification (there is NO On Wed Feb 06 08:03:27 2013, demerphq wrote:
|
From @doyOn Wed, Feb 06, 2013 at 07:45:45AM -0800, Victor Efimov via RT wrote:
Here, $x is false, so "$x && ..." evaluates to just $x, and so the first
Here, $x is not false, so "$x && $x->[0] =~ /abc/" evaluates to
There are several potential explanations here, relating to differences -doy |
From [email protected]Ok, thanks. On Wed Feb 06 08:19:45 2013, doy@tozt.net wrote:
|
[email protected] - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#116665 (status was 'rejected')
Searchable as RT116665$
The text was updated successfully, but these errors were encountered: