in reply to Re^6: To initialise or not to initialise?
in thread To initialise or not to initialise?

When you loop over a list, the local variable is aliased to each member of the list.

Yes, I got that part. The part that surprises me is that B::Deparse deparses it to something that doesn't work, and I always assumed that the deparsing was correct. Consider:

use strict; use warnings; foreach $_ (my ($foo, $bar, $baz)) { $_ = "default"; } print "$foo\n";
This code doesn't run, and it is what I mistakenly assumed your code was the equivalent of (minus the use's and print).

Replies are listed 'Best First'.
Re^8: To initialise or not to initialise?
by tilly (Archbishop) on Jun 24, 2004 at 23:30 UTC
    Ah. Because it scopes the variables differently depending on whether the loop is inline or not.
Re^8: To initialise or not to initialise?
by Hofmator (Curate) on Jun 25, 2004 at 08:42 UTC
    The part that surprises me is that B::Deparse deparses it to something that doesn't work, and I always assumed that the deparsing was correct.

    Isn't that the definition of a bug in B::Deparse then?

    I wanted to file a bug report, but rt.cpan.org doesn't know about 'B::Deparse'. Where should it be sent to? Or did you do that already?

    -- Hofmator

      B::Deparse is a core module, so it would go to p5p (or to PerlBug via perlbug). If you want to submit a bug report, search the p5p archives first (or bugs.perl.org), and I'm not sure if B::Deparse is suppose to guarantee perfectly accurate code.
        Thanks, I searched and found something similar, though not the same.

        Therefore I filed a new bug via perlbug, got ID #30504.

        -- Hofmator