This is really ugly, but if you have the memory to handle a file that might
only use \r, and you don't mind using a temp file for the processing, here
is one possibility.
open(file, "c:/blah/sample.txt") || die "$!\n";
open(tempfile, ">c:/blah/temp.txt") || die "$!\n";
foreach (<file>) {
s/\r|\r\n/\n/g;
print tempfile "$_";
}
close tempfile;
open (tempfile, "c:/blah/temp.txt") || die "$!\n";
foreach (<tempfile>) {
chomp;
print "$_\n" unless ($_ eq '');
}
Like I said, ugly, but it will work and give you a consistent file format to
work with in the second loop
Steve
-----Original Message-----
From: Sherlock Holmes [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 03, 2001 7:33 AM
To: [EMAIL PROTECTED]
Subject: Reading file line by line regardless of type of end-of-line?
I would like to create a perl script that reads lines from an ascii
file, but that reads them regardless of whichever of the three variants
(<CR>, <LF> or <CR><LF>) is actually in use as end-of-line, *without*
knowing beforehand which is the case. The script should run on many
systems (so installing a special version of Perl is out of the question).
Now perl has the input_line_separator which you can set to a value,
sadly though, it is not a regular expression. Which means that I am
looking for a trick or a method to handle text files line by line
regardless of end-of-line character.
Can anybody help me out?
Thanks,
SH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]