Looping between file to store text Perl -


sub open_file {     @files = @_;     @file_text = ();      foreach $file(@files){         open(my $fh, '<', $file);         @file_text = <$fh>;         close($fh);     }     return @file_text; } 

hi there. there seems problem coding particularly foreach loop part. @files array containing @files = (abc.html bcd.htm zxy.html); open these html files , store accumulative html texts in @file_text further use.

however getting error :

readline() on closed filehandle $fh @ source-1-2.pl line 36 readline() on closed filehandle $fh @ source-1-2.pl line 36 readline() on closed filehandle $fh @ source-1-2.pl line 36 

maybe getting 3 line of same error cause looping between 3 html/htm files.

perhaps check if open succeeded:

open(my $fh, '<', $file)     or die "can't open $file: $!"; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -