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 :-)
Cheers!

In reply to Opening multiple files simultaneously by chrishowe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.