in reply to How to test for a new line
I'd do something like (untested)
If you don't care to alert the user when newlines are found, then replace the if block withmy $myvar; { local $/ = undef; if ( ( $myvar = <FILEPTR> ) =~ s/\n+//g ) { alert_user(); } }
The line( $myvar = <FILEPTR> ) =~ s/\n+//g;
essentially turns off line-oriented input, and reading from the handle gets the whole string.local $/ = undef;
If you want to preserve the last newline (and just get rid of the embedded ones), use this regular expression instead:
s/\n+(?!\z)//g
the lowliest monk
|
|---|