in reply to Re: postfix syntax enlightenment
in thread postfix syntax enlightenment
The perlsyn doc on statment modifiers says that a line such as my $var = 1 if $test; leads to an undefined behaviour: you don't know what happens to the variable if the condition evaluates to false.
Are you sure of that? This is not what I understand from the document you quote. My understanding, from reading aforesaid document, is that my $var if $test; is undefined. But this is quite different. Please note that this is not a troll at all, I would really like to know. Although, in such a case, I would normally declare the variable and assign it in separate instructions, I think there might be some of my programs (at most very few) where I used something equivalent to my $var = 1 if $test; and I don't recall having encountered any problem with this type of syntax (but it is also quite possible that I actually never did it, I would in principle be suspicious with such a construct with conditional declaration).
This seems to work according to my expectations:
$ perl -e 'my $c = 1 if 1; print $c;' 1 ~ $ perl -e 'my $c = 1 if 0; print $c;'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: postfix syntax enlightenment
by kcott (Archbishop) on Mar 28, 2014 at 21:02 UTC | |
by Laurent_R (Canon) on Mar 28, 2014 at 22:57 UTC | |
by kcott (Archbishop) on Mar 29, 2014 at 09:01 UTC | |
by Laurent_R (Canon) on Mar 29, 2014 at 10:23 UTC | |
by Anonymous Monk on Mar 29, 2014 at 01:02 UTC | |
by Anonymous Monk on Mar 29, 2014 at 02:40 UTC | |
|
Re^3: postfix syntax enlightenment
by AnomalousMonk (Archbishop) on Mar 28, 2014 at 20:22 UTC |