in reply to my $x = <expr>; vs my $x; $x = <expr>;

No, but beware of
my $x = expresssion if condition
Which, due a bug in Perl, causes $x not to be cleared at the end of the block, and so to still have its old value on the next entry to the block, eg
for (1..3) { my $x = "foo\n" if $_ > 9999; print $x; $x = "bar\n"; }
which outputs:
Use of uninitialized value in print at /tmp/p line 5. bar bar

Dave.

Replies are listed 'Best First'.
Re^2: my $x = <expr>; vs my $x; $x = <expr>;
by Aristotle (Chancellor) on Jun 05, 2004 at 21:31 UTC
    It's not a bug, it's an accidental feature, and it only happens when the condition is false. It's because the dual nature of my, which has effects both at compile time and at runtime.

    Makeshifts last the longest.

      It's not a bug, it's an accidental feature
      Well, that's a matter of semantics:-) In 5.10.0 the form my $x if 0 will be officially deprecated, and will give a warning (and I should know - I added the warning!). It was felt that benefits of the "feature" for eg pseudo-static variables was outweighed by the unexpectedness of its behavour for most people.

      Dave.

        Per an email from Larry Wall, he calls it an "accident of implementation." It also has different behavior in differing versions, so I'm glad to see the warning being added. Though I'm not yet won over to the perl6 way of thinking about variable traits.

        --
        [ e d @ h a l l e y . c c ]