in reply to Re^3: postfix syntax enlightenment
in thread postfix syntax enlightenment
Hi Ken,
Thank you for your answer and I have usually the highest regard for your posts (and I upvoted your answer even though I still disagree with it, because I think it is well explained). To set the record straight, I am not trying to invalidate Eily's example, far from that, I am just trying to understand what exactly is undefined behavior here. And I am still not convinced at all that:
andmy $var if $test;
are equivalent in terms of the behavior being defined or not. These are two quite different types of statements. Assuming just one second, only for the sake of argument, they had both a defined behavior, I would still consider the first one as almost entirely useless (and deserving to be undefined), and the second one as making some sense (although lacking clarity, to say the least). Therefore, if the author of the documentation meant to say that my $var = 1 if $test; also has undefined behavior, then I would submit that this should probably be added to the documentation, because having someone using this second type of construct is much more likely than than the first one.my $var = 1 if $test;
Again, I am not saying that Eily is wrong, I just don't know and I truly would like to know. While I usually would probably not use something like:
I would really not swear that I have never used something like:my $var = 1 if $test;
And, as far as I can say, I would expect this to work fine.my $value = $1 if $foo =~ /^\w+(\d+)/; do_something($value) if defined $value;
Concerning the one-liners, I agree that they were very short examples I added at the last minute to my post, this is an improved version of them:
I am not saying that observed behavior is describing the Perl standard, but since there is no real Perl 5 standard, in a certain way, only the compiler can tell us what to think when the documentation is ambiguous. And I think the documentation is definitely ambiguous in that specific case. Having said that, I perfectly understand the warning: "Future versions of perl might do something different..." Just not sure that it applies to something like:$ perl -Mstrict -Mwarnings -e ' my $c = 1 if 1; print $c;' 1 ~ $ perl -Mstrict -Mwarnings -e ' my $c if 1; print $c;' Use of uninitialized value $c in print at -e line 1.
my $var = 1 if $test;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: postfix syntax enlightenment
by kcott (Archbishop) on Mar 29, 2014 at 09:01 UTC | |
by Laurent_R (Canon) on Mar 29, 2014 at 10:23 UTC | |
|
Re^5: postfix syntax enlightenment ( y $x if 0; Trick my @array = () if 0; conditional declaration; state )
by Anonymous Monk on Mar 29, 2014 at 01:02 UTC | |
|
Re^5: postfix syntax enlightenment
by Anonymous Monk on Mar 29, 2014 at 02:40 UTC |