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

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 $_; }

Replies are listed 'Best First'.
Re^7: inserting array of data into text file
by dragonchild (Archbishop) on Jul 13, 2004 at 15:25 UTC
    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
        At this point, I'm going to stop trying to read your mind. If you want me to help further, you will need to provide the following:
        1. A set of unambiguous requirements describing exactly what this program is supposed to do
        2. A set of example inputs
        3. A set of expected outputs

        No code. Just those documents.

        ------
        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

Re^7: inserting array of data into text file
by ysth (Canon) on Jul 13, 2004 at 18:35 UTC
    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);
        Close OUT before opening COL.

        What exactly is the problem you are seeing?