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
In reply to Re^3: postfix syntax enlightenment
by kcott
in thread postfix syntax enlightenment
by RobertCraven
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |