Perl Monk, Perl Meditation | |
PerlMonks |
Changing local variables in subroutine by passing by reference?by why_bird (Pilgrim) |
on Feb 29, 2008 at 09:54 UTC ( [id://671135]=perlquestion: print w/replies, xml ) | Need Help?? |
why_bird has asked for the wisdom of the Perl Monks concerning the following question: Dear Monks, Me again.. this time I'm having a problem with changing values in a subroutine. When a certain event occurs (my data returns '0' or 'inf') I need to print some things to a file (that's fine) and then clear the values of some other variables, to start again. The array of data is determined by the main body of the program and is normally reset at the end of the while loop, and the counter counts from (say) 1 - 10 during the loop and again needs to be reset at the end of the loop. My variables are locally scoped, so if I try changing them directly in the subroutine, nothing happens: (as expected)
So then I tried passing by reference:
That prints Thanks!
Back to
Seekers of Perl Wisdom
|
|