in reply to Re^3: inserting array of data into text file
in thread inserting array of data into text file

with  $_ =~ s/^(\S\s+\S)/$1, $col[$i++]/e; stops in the same place? does this point to a key problem?

Replies are listed 'Best First'.
Re^5: inserting array of data into text file
by dragonchild (Archbishop) on Jul 13, 2004 at 14:13 UTC
    Without seeing the rest of your code, I can provide no further help.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      this is main code causing the problem
      print "Testing File:\n"; $file = <STDIN>; print "Output File:\n"; $file2 = <STDIN>; open (FILE, "<$file"); open (OUT, ">TRUE_OUTPUTS"); open (FILE2, "<$file2"); open (OUT2, ">COMPARE"); while (<FILE>) { if ($_ =~ m/^\d\s+\d/) {print OUT $_} } while (<FILE2>) { push @col, $_ =~ m/(\S+\s+\S+)/; } close(COL); print (OUTPUT @col); $size = scalar @col; print $size; open(COL, "<TRUE_OUTPUTS"); while(<COL>) { $_ =~ s/^(\S\s+\S)/$1 $col[$i++]/; print OUT2 $_; }
        If that is all the code, you have a few issues:
        1. You don't use strict or warnings. Turning them on will be very instructive and helpful.
        2. You close the filehandle COL without opening it.
        3. Why aren't you just appending?
          my $i = 0; while (<COL>) { print OUT2 "$_ ", $col[$i++], "\n"; }

        You made it more complicated than it needed to be.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

        There don't seem to be many comments in that code, or helpful things like "use warnings;". Try closing OUT before opening COL. What is OUTPUT? Are there perhaps some files whose last line is missing a newline character? Try chomping all your input and adding "\n" to each print.