Loading ...
Sorry, an error occurred while loading the content.

Re: Help...reading a file and open files based on list.

Expand Messages
  • buxh42a
    ... You are getting the contents of filename.in because you are printing it yourself with print $line ; You really shouldn t expect to see the contents of a
    Message 1 of 3 , Dec 1, 2004
    • 0 Attachment
      --- In perl-beginner@yahoogroups.com, "markev_123" <markev_123@y...>
      wrote:
      >
      >
      >
      >
      > open XFILE, "< filename.in" or die qq(Cannot open file test.pl: $!);
      >
      > @filecontent = <XFILE>;
      > foreach $line (@filecontent) {
      >
      > open INFILE, "< $line" or die qq(Cannot open
      > file "$line": $!);
      > print INFILE;
      > close (INFILE);
      >
      > print "$line";
      > }
      > close (XFILE);

      You are getting the contents of filename.in because you are printing
      it yourself with 'print "$line"';

      You really shouldn't expect to see the contents of a file by just
      printing the filehandle variable - print INFILE; is not going to do
      it. Try this:


      open XFILE, "< filename.in" or die qq(Cannot open file test.pl: $!);

      @filecontent = <XFILE>;
      #you can close XFILE here since you don't need it anymore
      close (XFILE);

      foreach $line (@filecontent)
      {
      chomp ($line);
      open INFILE, "<$line" or die qq(Cannot open file "$line": $!);
      @printit = <INFILE>;
      #close it first, since you may have some buffer issues
      close (INFILE);
      print @printit;
      }


      This should work. Also, try using "use strict" in the future, this
      may help you cut down on any hidden bugs.

      Sam
    Your message has been successfully submitted and would be delivered to recipients shortly.