http://www.perlmonks.org?node_id=294172


in reply to Re: weird perl verion and/or OS problem with newlines
in thread weird perl verion and/or OS problem with newlines

Thanks for the quick response. I think a little more explanation is in order on my part. I have a file with multiple concatenated sections that begin with #:lav and end with #:eof and I want to process each of these one at a time e.g.
--start of file-- #:lav some text #:eof #:lav some text #:eof #:lav some text #:eof --end of file--
This is why I used the while loop with the concatenated string... so I can do some processing of the subsections that I find that satisfy the above criteria. Writing a while loop to process the code line by line would be more efficient in memory, but more time in development. Vince

Replies are listed 'Best First'.
Re^3: weird perl verion and/or OS problem with newlines (tye)
by tye (Sage) on Sep 25, 2003 at 16:02 UTC

    <IN>; # skip "--start of file--" while( <IN> ) { if( $_ eq "#:lav\n" ) { local $/= "#:eof\n"; my $block= <IN>; # ... process $block here ... } elsif( $_ eq /^--end of file--/ ) { warn "Unexpected line: $_"; } }

    Updated: Thanks to graff for noting that I wrote $\ when I meant $/.

                    - tye