P is for Practical | |
PerlMonks |
declare my variable in loopby gauss76 (Scribe) |
on Aug 08, 2017 at 08:11 UTC ( [id://1196954]=perlquestion: print w/replies, xml ) | Need Help?? |
gauss76 has asked for the wisdom of the Perl Monks concerning the following question: Hi Perl Monks, I am fairly new to Perl and have recently produced the following piece of code. I have tested it extensively and it returns the desired results. However I just wondered if someone with more experience of Perl could advice me on its usability. Basically, I have declared an array variable with the 'my' keyword inside a for loop. I then use the address of this declared array variable in another array variable that has been declared before the aforementioned for loop. The basic code structure looks like this:
The @Array_Vals variable is, in general, a different size each time. In addition the array @Array_Vals defined inside the loop is not used anywhere else in the code and is local to the for loop. My concern is with the declaration of the array within the for loop. Even though the name of the variable is the same each time I assume for each loop it gets assigned to a different memory address thus the values in the @Array_of_ALL_Vals array do not get overwritten? I thought it would be better to add an incrementer to the array name inside the for loop so the name would be different each time (@Array_Vals1,@Array_Vals2,...). However after doing some searches I found that would not be a good idea (variable name containing variable) Many thanks for any comments Gauss76
Back to
Seekers of Perl Wisdom
|
|