in reply to Reading a file with 8kB long lines

I don't think your diagnosis is correct. My perl can read long lines with no problem:

$ perl -e 'for (1 .. 10) { print("A" x (9000 + $_) . "\n") }' > fil +e.txt $ perl -le 'open FOO, "file.txt"; print length $_ for (<FOO>);' 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011

What version of Perl are you running? What OS? Can we see the real code, please?

-sam

Replies are listed 'Best First'.
Re^2: Reading a file with 8kB long lines
by gri6507 (Deacon) on Jun 08, 2007 at 21:12 UTC
    D'oh. You are right. I thought that the wrapping of the long lines was because of the text editor. I opened up my file in a hex-viewer and that confirmed it - this text file has newlines sprinkled throughout the "long lines". So, now I have to figure out how to parse this file.

    I'd like to hear your suggestions. The file is kind of C-code like (but it isn't - it's actually an SVF JTAG Boundary scan file) and looks like this

    // comments some code; more code; // more comments some very long long long code;
    basically, I want to read in every line that does not begin with a "//" and ends with a ";". Should I just set $/ to ';' and then process the read in strings to drop everything between // and \n?
      You can't set the input delimeter unless you know more than you've told us about comment lines.

      I'd do something like:

      my $full_line = ''; while ( my $line = <FH> ) { chomp $line; next if substr( $line, 0, 2 ) eq '//'; $full_line .= " $line"; # space wanted? your call! next unless substr( $line, -1, 1 ) eq ';'; #do something with $full_line print "$full_line\n"; $full_line = ''; }
      Update: replace the $full_line .= line with

      $full_line .= $full_line eq '' ? $line : " $line";

      Update^2: I should have said this has been tested and produced the following with your sample data:

      some code; more code; some very long long long code;
Re^2: Reading a file with 8kB long lines
by blazar (Canon) on Jun 09, 2007 at 15:51 UTC

    First of all: ++. Then (I wanted to /msg you, but it resulted to be longer than expected, so:)

    $ perl -le 'open FOO, "file.txt"; print length $_ for (<FOO>);'

    Ok, they're just ten lines so it doesn't make a difference, but we recommend people all the time not to slurp files in all at once if possible and since we're talking about oneliners anyway, I would rewrite them like thus:

    $ perl -le 'print "A" x (9000 + $_) for 1..10' > file.txt $ perl -lpe '$_=length' file.txt 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010