KAKAK
KAKAK

Reputation: 899

Storing texts from many files in an array using foreach Perl

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

    foreach my $file(@files){
        open(my $fh, '<', "./DATA/" . $file) or die "can't open $file: $!";
        @file_text = <$fh>;
        close($fh);
    }
    print "@file_text";
}

Having problems concatenating texts from 3 different .html files into one array @file_text

So far the script only stores the text into @file_text from the very last .html file it loops through.

Upvotes: 0

Views: 62

Answers (1)

Orab&#238;g
Orab&#238;g

Reputation: 11992

Of course, as you erase the last value of @file_text each time with the line

@file_text = <$fh>;

you should replace this line with

push (@file_text, <$fh>);

Upvotes: 3

Related Questions