wackattack has asked for the wisdom of the Perl Monks concerning the following question:

I have a txt file of 2106 numbers like so:
0.004
0.003
0.004
0.006
0.006
0.008
0.006
0.006
0.006
0.005
0.006
0.007
0.007
It's nothing fancy, just a list of numbers. I run this exact perl code on it:
open(INPUT2, "$ARGV[0]" . "_RMS") or die $!; open(DEBUG2,">debug2") or die $!; while(defined ($line = <INPUT2>)){ print DEBUG2 $line; } close(INPUT2); close(DEBUG2);
and the copied file is only 2048 numbers long. I've opened both files with vim and :set list. I see nothing wrong in the data file. I just seemed to stop 58 numbers short of the end of the file. I had our system admin look at it and he can't figure it out. I am in complete dismay.

Replies are listed 'Best First'.
Re: Bug in perl?
by GrandFather (Saint) on Apr 11, 2007 at 20:42 UTC

    You might delete the first 10 lines of the input file and see if the problem line remains at 2048 (which pushes things into bug territory) or moves to 2038 (which indicates a file data problem).

    If all else fails tack the input file data to the end of your script and print to STDOUT. Verify the problem still exists and post the code here. It would look something like:

    use strict; use warnings; while (defined (my $line = <DATA>)){ print $line; } __DATA__ 0.004 0.003 0.004 0.006 0.006 0.008 0.006 0.006 0.006 0.005 0.006 0.007 0.007

    DWIM is Perl's answer to Gödel
Re: Bug in perl?
by samtregar (Abbot) on Apr 11, 2007 at 18:58 UTC
    What's on the 2048th and 2049th lines?

    -sam

Re: Bug in perl?
by Krambambuli (Curate) on Apr 11, 2007 at 20:17 UTC
    Is it possible that you're so low on disk space that you're just hitting the wall when reaching line 2048 ?

    You'll probably have to first try to decide if it's a problem with the input file or something wrong when it comes to output.

    Try to also print to STDOUT just to verify that the problem is rather with the input then with the output:
    my $line_number = 1; while(defined ($line = <INPUT2>)){ print $line_number++, ": ", $line; print DEBUG2 $line; }
    Do you see all the lines or would the numbering stop after 2048 ?
    Do you see that the 2048: line is the last ?
Re: Bug in perl?
by graff (Chancellor) on Apr 12, 2007 at 13:09 UTC
    Just in case you're running this on ms-windows, you might want to try adding  binmode INPUT2 just before the while loop. And in that case, you might also want to add something like this inside the while loop:
    if ( $line =~ /\cZ/ ) { warn "found DOS end-of-text-file marker at line $.\n"; }
    Just a guess...
Re: Bug in perl?
by BrowserUk (Patriarch) on Apr 11, 2007 at 19:51 UTC