I am looking for a way to clear all my arrays in a Perl program.
I am currently calling a routine that explicitly "flushes" all arrays:
sub clear_arrays{(@array1,@array2,@array3)=((),(),());}
This makes me find all the arrays in the program and literally refer to them in the subroutine.
I looked at perldoc for reset , undef and delete , but couldn't interpret them to clear all arrays.
Is there a built-in Perl function that can do this?
If not, is there a function that returns an array of all array variables?
Example:
my @prog_arrays = getarrays(); foreach(@prog_arrays){$_ = ();}
Where getarrays() can be a Perl built-in function that returns all / all initialized arrays in a program.
EDIT:In my specific situation, only two global arrays are involved, which should be reset. I expanded this question out of curiosity, not out of necessity. Basically, my global values are
@email_subject and
@email_msg .
They have values that are inserted into them as the script progresses, and the data is collected / analyzed. An email is sent at the end of the script, and the script may run again depending on the loop condition variable.
If it starts up again, I need to clear these 2 globals so that they can be aggregated again during the next cycle of the cycle. It doesn’t kill me to clear these two arrays using a literal link, but I was just wondering if Perl has a built-in function to clear arrays without referencing them.
This may not be the best way to accomplish this, but it was the first intuitive option that I considered.