in reply to Re: Reading a file with 8kB long lines
in thread Reading a file with 8kB long lines

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?

Replies are listed 'Best First'.
Re^3: Reading a file with 8kB long lines
by FunkyMonk (Bishop) on Jun 08, 2007 at 21:28 UTC
    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^3: Reading a file with 8kB long lines
by BrowserUk (Patriarch) on Jun 08, 2007 at 21:40 UTC