well the code loads a file into an array line by line. However it certainly isn't the most optimal way to do this. At least I certainly wouldn't do it this way.
sub load_array($$)
{
#the first element we pass to this function is a
#array reference, the second is the name of a file
my ($a_ref, $file) = @_;
#attempt to open the file or quit executing our program
open (FILE, $file) or die "Can't open $file:$!\n";
#take all the lines in the file, and put them into the
#array that $a_ref points to.
@{$a_ref} = <FILE>;
# close the file... duh I guess
close FILE;
# remove all of the carriage returns from the end of
# each element in the array
chomp @{$a_ref};
}
# to call this routine
my @array;
&load_array(\@array, # pass in the reference to the array
"test.txt"); # the name of our file
Personally I think I would rewrite this to do something like:
sub load_array {
my $file = shift; # the first parameter is our file
my @array;
open(IN, $file) or die "Can't open $file: $!\n";
# for every line in the file...
while(<IN>) {
chomp; # remove the trailing carriage return
# could also be chomp $_;
push @array; # put it into our array
# could also be push @array, $_;
} # while
close(IN);
return @array;
} # load_array
# to run this routine...
my @array = &load_array("test.txt");