Looping between file to store text Perl

sub open_file {
    my @files = @_;
    my @file_text = ();

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

Hi there. There seems to be a problem with this coding particularly the foreach loop part. @files is an array containing @files = (abc.html bcd.htm zxy.html); I would like to open all these html files and store the accumulative html texts in @file_text for further use.

However i am getting error :

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

Maybe i am getting three line of same error cause i am looping between 3 html/htm files.

Answers


Perhaps check if the open succeeded:

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

Need Your Help

why is php generating the same session ids everytime in test environment (WAMP)?

php unique wamp logout sessionid

i've configured wamp in my system, and am doing the development cum testing in this local environment. i was working on the logout functionality, and happened to notice that the session ids being

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.