Hi All,
I am trying to open multiple files at the same time, with the aim of working through a file opening another file halfway through reading the first file, reading the second file, and then jumping back to the original file. Something like reading a webpage, following a link, reading the linked page, and then going back to the original page where you left off.
My skeleton code is below, but it doesn't work. It opens the two files but will only read the second file and not the first one. I know it is something to do with the filehandles going wrong, but I don't know what to do to correct it!
use strict;
my @filestack;
my $datafile = "text1.txt";
my $handle;
my $i = 0;
my @raw_data;
open ($handle, $datafile);
push (@filestack, $handle);
$datafile = "text2.txt";
open ($handle, $datafile);
push (@filestack, $handle);
foreach my $file(@filestack){
print "$i\n";
@raw_data=<$file>;
foreach my $temp(@raw_data){
print "$temp\n";
};
close($file);
$i++;
};
Any help would be appreciated :-)