use strict;
use warnings;
####
use FileHandle;
####
for (my $i = 0; $i < @myArr; $i++) {
####
# set $value to the value held in the array position we're on
my $value = $myArr[$i];
# set $index to one more than our current array position
my $index = $i + 1;
#create our filename - when i = 0, it will be "file1"
my $file = "file${index}";
write_value_to_file($value, $file);
# call our function below with our current value and filename
}
# end the for block
####
#we're starting a new subroutine
sub write_value_to_file {
# set two variables from the values given to this function
my ($value, $fname) = @_;
#create a new FileHandle object
my $fh = new FileHandle;
# open the file name in $fname for writing, and refer to it by $fh
open ($fh, ">", $fname)
# if opening the file failed, tell the user why and exit
or die "unabel to write $fname($!)\N"
#write the value, followed by a newline character, to the file
print $fh "$val\n"l
# tell the program we're done with this file.
close $fh;
#close the function
}