in reply to Re^2: postfix syntax enlightenment
in thread postfix syntax enlightenment
The documentation that Eily references says this:
NOTE: The behaviour of a my, state, or our modified with a statement modifier conditional or loop construct (for example, my $x if ...) is undefined. The value of the my variable may be undef, any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons.
The example it gives is:
my $x if ...
The example you give is:
my $var if $test;
I see nothing that invalidates Eily's example of:
my $var = 1 if $test;
Another important point from that is: "Future versions of perl might do something different from the version of perl you try it out on."
I don't think showing us the results of just two tests is particularly meaningful.
[While it's probably a moot point, your second one-liner (with my $c = 1 if 0) doesn't indicate whether $c's value is a zero-length string or undef.]
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: postfix syntax enlightenment
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 |