Posted By


Mazzaroth on 02/19/11

Tagged


Statistics


Viewed 150 times
Favorited by 1 user(s)

load_file_in_array()


/ Published in: Perl
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.