... what if my is within the condition of a postfix if? ... is it valid?

This is the way I look at it: The thing to remember is that the modifier clause (if that's the proper terminology) of a modified statement modifies the behavior of the statement. In order to do so, the modifier clause must always be evaluated. The ambiguity in a statement like
    my $x if $some_conditional;
concerns whether (and when) the lexical definition is evaluated, but  $some_conditional (or whatever expression may be there) must always be evaluated.

In a statement like
    0 if my $x = 1;
there is no ambiguity: the lexical is always defined (and, in this example, initialized). Similarly, in the statement
    do_something($_) for my @ra = @rb;
the for-loop initialization expression  my @ra = @rb must always be evaluated (including the definition and initialization of its lexical) in order that for may be able to control (i.e., modify the behavior of) the statement.

So, is
    0 if my $x;
and its ilk valid? Unquestionably (and unambiguously and without deprecation) yes, I would say. (But I'm too lazy right now to dig up a documentation citation.)

Consider the following code. Also consider running | compiling it with  -MO=Deparse,-p added (often enlightening in these cases).

c:\@Work\Perl\monks>perl -wMstrict -le "no warnings 'syntax'; ;; 0 if my $x = 42; print qq{$x}; ;; my @orig = qw(foo bar baz); tr{a-z}{A-Z} && printf qq{'$_' } for my @copy = @orig; print ''; print qq{(@orig) (@copy)}; ;; for (0 .. 2) { die 'Oops...' if my $x; print qq{\$x (still) undefined here} if not defined $x; $x = 42; print qq{\$x is $x here}; } " 42 'FOO' 'BAR' 'BAZ' (foo bar baz) (FOO BAR BAZ) $x (still) undefined here $x is 42 here $x (still) undefined here $x is 42 here $x (still) undefined here $x is 42 here

(Also consider running your code with warnings enabled. And strict.)


In reply to Re^3: postfix syntax enlightenment by AnomalousMonk
in thread postfix syntax enlightenment by RobertCraven

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.