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} = ; # 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 #### 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() { 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");