R
Robert Wallace
i made a dos to unix, unix to dos program catered for my own purposes.
it's seems to work fine. small program, 26 lines
anyone see any potential problems with it? do you have a better way to
do it?
my next step is to slip in some code to automatically "detect" whether
its a unix or dos file.
#!/usr/bin/perl -w
use strict;
#setting based on filename argument.
# if sym link is dos-unix or if sym link is unix-dos
my ($from, $to);
my $option=substr($0,rindex($0,'/')+1,length($0)-1); # $0 gives full
path. this code gives just filename
if ($option eq "dos-unix"){
$from="\015\012";
$to ="\012";
} elsif ($option eq "unix-dos"){
$from="[^\015]\012";
$from="[^\015]\012";
$to ="\015\012";
} else {
print "only sym links \"unix-dos\" and \"dos-unix\" are allowed\n";
}
foreach my $file (@ARGV){
my @output;
open READ, $file or die "Could not open file '$file' $!";
while (<READ>){
$_=~s/\Q$from/$to/;
push @output, $_;
}
close (READ);
open WRITE, ">$file" or die "Could not open output file '$file' $!";
print WRITE @output;
close (READ);
}
it's seems to work fine. small program, 26 lines
anyone see any potential problems with it? do you have a better way to
do it?
my next step is to slip in some code to automatically "detect" whether
its a unix or dos file.
#!/usr/bin/perl -w
use strict;
#setting based on filename argument.
# if sym link is dos-unix or if sym link is unix-dos
my ($from, $to);
my $option=substr($0,rindex($0,'/')+1,length($0)-1); # $0 gives full
path. this code gives just filename
if ($option eq "dos-unix"){
$from="\015\012";
$to ="\012";
} elsif ($option eq "unix-dos"){
$from="[^\015]\012";
$from="[^\015]\012";
$to ="\015\012";
} else {
print "only sym links \"unix-dos\" and \"dos-unix\" are allowed\n";
}
foreach my $file (@ARGV){
my @output;
open READ, $file or die "Could not open file '$file' $!";
while (<READ>){
$_=~s/\Q$from/$to/;
push @output, $_;
}
close (READ);
open WRITE, ">$file" or die "Could not open output file '$file' $!";
print WRITE @output;
close (READ);
}