Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Unix and Windows CRLF vs LF

by SavannahLion (Pilgrim)
on Jun 05, 2009 at 06:40 UTC ( [id://768683] : note . print w/replies, xml ) Need Help??


in reply to Unix and Windows CRLF vs LF

Thank you for your help. Ultimately, I found a hint at http://perldoc.perl.org/perlfaq6.html describing a method on file streaming. The specific code example I ended up studying (took me about three hours of reading to figure out what (?s) did. Another hour to figure out why $_ needed to be localized.) is:
local $_ = ""; while( sysread FH, $_, 8192, length ) { while( s/^((?s).*?)your_pattern/ ) { my $record = $1; # do stuff here. } }
Yes, I know the bug in this example. It's exactly how it is on the perldocs. Took me about an half hour of debugging to figure it out. Just about drove me nuts.
In any case, many thanks for the pointers, tips and hints. I needed some starting points and that is exactly what I got.

Replies are listed 'Best First'.
Re^2: Unix and Windows CRLF vs LF
by ikegami (Patriarch) on Jun 05, 2009 at 08:46 UTC

    Another hour to figure out why $_ needed to be localized

    Because you change its value. Clobbering your caller's variables isn't nice.

    Yes, I know the bug in this example. It's exactly how it is on the perldocs

    perlbug