From perlsyn:

NOTE: The behaviour of a my statement modified with a statement modifier conditional or loop construct (e.g. 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.

I think that's clear enough. And perlsyn is far from obscure documentation.

Update:

Perl doesn't natively complain to you if you use such a construct. However, there's a tool that I have in my arsenal which is so simple to use that I've managed to make it a habit as I work on scripts. Start with Perl::Critic. Next, create a Perl script based on the synopsis of Perl::Critic's documentation, as follows:

use Perl::Critic; my $file = shift; my $critic = Perl::Critic->new(); my @violations = $critic->critique( $file ); print @violations;

Now, name that script 'criticize', and put it in your favorite toolbox bin directory. Finally, as you're composing scripts, periodically pass it through the complaint department like this:

criticize mytest.pl

And the output for the specific 'violation' we're discussing:

Variable declared in conditional statement at line 9, column 1. Declar +e variables outside of the condition.

Dave


In reply to Re: scope of an autovivified variable? by davido
in thread scope of an autovivified variable? by rmcgowan

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.