On Dec 8, 2005, at 16:35, Frank Bax wrote:
What's the correct way to trim trailing newlines from a text file
that might be either DOS or UNIX format for newlines? The docs (and
my experience) is that chomp only works properly if the text file
is native to the current operating system? I'm running on *bsd
system.
If you do not know the convention in the file beforehand, it is
easier to use s///:
# Chomp lines of text files with newline conventions
# of either DOS or Unix in a script running on Unix.
while (my $line = <FH>) {
$line =~ s/\015?\012//; # hand-made chomp
# ...
}
That is just an example, once you understand the basics of newlines
and I/O these tricks are apparent.
Just for the record, maybe it would be worth having a look at
File::SmartNL, or the :crlf layer PerlIO provides in recent perls
(see perldoc PerlIO).
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>