Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Array name with a Variable

by chromatic (Archbishop)
on Apr 17, 2008 at 20:31 UTC ( #681291=note: print w/replies, xml ) Need Help??

in reply to Re: Array name with a Variable
in thread Array name with a Variable

my ( %union, %intersect ) = ( (), () );

That seems a little extravagant. Do you often have problems with freshly-declared hashes not being empty?

Replies are listed 'Best First'.
Re^3: Array name with a Variable
by mr_mischief (Monsignor) on Apr 17, 2008 at 20:38 UTC
    No, I don't have that problem. It is superfluous. For some reason I was in the mindset that the example of how to assign to more than one variable might be useful to the OP, but I should've done that with @array1 through @array4 if I wanted to make that point I guess.

      A fair point. It was a strange construct I've never seen before, and I wondered at the motivation.

        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). ;-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://681291]
[Tanktalus]: Wow, given the time separation of marioroy's oatmeal cookies and Disciplulus' response, I'm amazed that marioroy responded :)
[Discipulus]: no no seriously, redss posed a good question in the right moment, and you gave as always wonderful answers
[Discipulus]: Tanktalus my comment was about how to fork & join in tk?
[marioroy]: Oh, I've might of missed Discipulus's earlier response. I had gone to bed.
[Tanktalus]: ah, I don't even have the perlmonks site open in my browser :)
Tanktalus is chatting through his cbstats application :)
[marioroy]: Perl is so much fun.
[Discipulus]: Tanktalus i recently started a Meditation about marioroy's MCE suit of modules, but is even better to see a practical question answered than responses to my meditation

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2017-04-23 19:47 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.