Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, I think more specifically why the assignment and the declaration ended up inside the loop together that way was that I followed basically these steps:

  1. copied the original code with the declaration at the top
  2. modified the code to clear the hashes inside the loop to reuse them
  3. noticed the hashes weren't actually used outside the loop
  4. moved the "my" inside the loop with the assignment
  5. stopped, not paying any attention to the fact that I now had a useless assignment.

So you can see it was at some point useful, but I actually added smell to that portion of the code by refactoring carelessly. That's something to consider when thinking about changing working code, I guess.

Update: I guess the above should say I put the code to clear the hashes inside the wrong loop the first time around. See Re^3: Array name with a Variable for a corrected version (or see the responses by those who didn't screw up the scoping in the first place). ;-)


In reply to Re^5: Array name with a Variable by mr_mischief
in thread Array name with a Variable by godevars

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found