On Mon, 18 Aug 2003, $Bill Luebkert wrote:

> Peter Eisengrein wrote:
>
> > Here's a simple unix2dos script to save you from having to do the MS
> > Word conversion in the future.
> >
>
> This script will only work on a Windoze system of course:
>
> > ### unix2dos.pl
> >
> > use strict;
> > use File::Copy;
> >
> > my $file = $ARGV[0] || die "Usage: $0 filename\n";
> > my $temp = "$ENV{TEMP}/$file\.$$";
> >
> > open(FILE,$file) || die "Can't open $file for reading : $!\n";
> > open(TMP,"> $temp") || die "Can't open $temp for writing : $!\n";
> >
> > foreach my $line(<FILE>)
> > {
> >         chomp($line);
> >         print TMP "$line\n";
>
> The above two lines could just as easily be:
>       print TMP $line;
> since the newline is just being removed and added right back.
>
> > }
> >
> > close(FILE);
> > close(TMP);
> >
> > move("$file","$ENV{temp}");
> > move("$temp","$file");
> >
> > ### end
>
> Or you could just use (on either UNIX or Windoze):
>
> #!perl -pi.bak
> BEGIN { binmode STDIN; binmode STDOUT; }
> s/[\r*\n*]+$/\r\n/;
> __END__
>
> or simply from the commandline (Windoze only version):
>
>       perl -pi.bak -e "" test.txt
>
> Perl can handle either UNIX or Windoze line endings on a Windoze system.
> UNIX can handle windoze line endings (except on the shebang line when
> started as 'scriptname' instead of 'perl scriptname', since the shell
> will barf on the \r).
>

And of course in the four lines:

foreach my $line(<FILE>)
{
        chomp($line);
         print TMP "$line\n";

could have been replaced with:

print TMP foreach (<FILE>);

or if the file was of reasonable size:

print TMP <FILE>;

On the other hand with the script:

#!perl -pi.bak
BEGIN { binmode STDIN; binmode STDOUT; }
s/[\r*\n*]+$/\r\n/;
__END__


I can't figure out why you would want to replace the first string of one
or more consecutive '*' characters on each line with "\r\n" while ignoring
the ending of that line. Or, for that matter why you would want to replace
the "\r" with "\r\n" unless you were trying to create a double spaced
version of the file. I suspect you were intending to instead do:
s/\r?\n/\r\n/;

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****



_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to