Sorry for the off-topic post, but I did feel the need to defend myself.
:)
#define FLAME_ON
On Wed, 28 Apr 1999, Matthew Kirkwood wrote:
> On Wed, 28 Apr 1999, Shane Kerr wrote:
>
> > You don't need a special program for this. Try:
> > perl -pe 's/\r$//' < input > output
> >
> > Perl is fun! Whee!!!
>
> And slow.
>
> tr -d '\r' <input >output
>
> Is what I use (though granted, it doesn't do exactly the same as the
> above).
Most DOS text files are relatively small. Even so, I ran the following
test on a Sparc 5 here at work (a slow old Sun computer):
kerr@bang [~/work]ls -l shani.tmp2
-rw-rw-r-- 1 kerr staff 5172498 Apr 28 12:04 shani.tmp2
kerr@bang [~/work]time tr -d '\15' < shani.tmp2 > /dev/null
real 0m2.925s
user 0m2.603s
sys 0m0.283s
kerr@bang [~/work]time perl -pe 's/\r$//' < shani.tmp2 > /dev/null
real 0m6.255s
user 0m5.872s
sys 0m0.321s
kerr@bang [~/work]
I wouldn't say that taking 6 seconds to convert a 5 Mbyte file is "slow".
While it is twice as slow as the tr program, that's only a 3 second
difference. Unless you want to convert a LOT (hundreds or thousands) of
files, or are going to have to do so on a regular basis (you have a DOS
program generating files and don't have the source), it doesn't matter.
It certainly doesn't matter enough to send an e-mail to the world
proclaiming the Perl command "slow". :P
Also note that the extra 3 seconds gives you a program that only converts
^M^J pairs, not every ^M that it finds in the file. And if you're feeling
really zealous, you can extend it to check for the terminating ^Z
mentioned earlier, although that actually does kill performance:
kerr@bang [~/work]time perl -pwe\
> 'if (/\032/) { s/([^\032]*).*/$1/; print; exit} s/\r$//'\
> < shani.tmp2 > /dev/null
real 0m7.494s
user 0m7.043s
sys 0m0.359s
kerr@bang [~/work]
Yikes! Seven and a half seconds! That means we can only process
650 Kbyte/sec!!! That _is_ slow. Especially with all of those 25 Mbyte
source files lying around.
Shane