Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^6: To initialise or not to initialise?

by tilly (Archbishop)
on Jun 24, 2004 at 23:19 UTC ( #369516=note: print w/replies, xml ) Need Help??


in reply to Re^5: 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. If you modify the variable, then you modify the original member of the list as well.
  • Comment on Re^6: To initialise or not to initialise?

Replies are listed 'Best First'.
Re^7: To initialise or not to initialise?
by runrig (Abbot) on Jun 24, 2004 at 23:27 UTC
    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).
      Ah. Because it scopes the variables differently depending on whether the loop is inline or not.
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://369516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2021-11-27 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?