Posted By

Mazzaroth on 02/19/11


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

wirenaught
wheffner


load_file_in_array()


 / Published in: Perl
 

Load a text file into an array. Remove all CR/LF.

  1. #------------------------------------------------------------------------------
  2. # sub load_file_in_array():
  3. # Load a text file into an array. Remove all CR/LF.
  4. #
  5. sub load_file_in_array {
  6. (my $a_file) = @_;
  7. my @the_lines = ();
  8.  
  9. unless ("$a_file" eq "")
  10. {
  11. # load the test case file
  12. if ($DEBUG > 1) { print "# loading the file '$a_file'\n" };
  13. unless ( open ( FILE, $a_file ) )
  14. {
  15. die "ERROR: $PROGNAME: Can't open '$a_file': $!";
  16. }
  17. @the_lines = <FILE>;
  18. close FILE;
  19. chomp(@the_lines);
  20. }
  21. return @the_lines;
  22. }

Report this snippet  

You need to login to post a comment.