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

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

  • Comment on Re^5: inserting array of data into text file

Replies are listed 'Best First'.
Re^6: inserting array of data into text file
by Anonymous Monk on Jul 13, 2004 at 14:20 UTC
    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

        sorry still does not use the whole contents of the array. I need it in column data so its easier to manuplate later
      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.
        with warning -w i am getting no feedback at all this si the code i have just tried, with no success in completing the task!
        open (FILE, "<$file"); open (OUT, ">TRUE_OUTPUTS"); open (FILE2, "<$file2"); open (OUT2, ">COMPARE"); while (<FILE>) { chomp $_; if ($_ =~ m/^\d\s+\d/) {print OUT "$_\n"} } close (FILE); while (<FILE2>) { chomp $_; push @col, $_ =~ m/(\S+\s+\S+)/; } close (FILE2); $size = scalar @col; print $size; open(COL, "<TRUE_OUTPUTS"); while(<COL>) { chomp $_; $_ =~ s/(\S\s+\S)/$1 $col[$i++]/; print OUT2 "$_\n"; } close(COL); close(OUT2);