A> Thanks for constructive remarks, here is the fixed one, which, again,
A> works just fine
and looks ugly too!
A> sub toUnixFile {
A> my ($file, $trim) = @_;
A> -f $file || die "Can't open \"$file\": $! \n";
lose the \ there. use an alternative delimiter
A> my $temp_file = $file . ".tmp.$$.$^T";
use the File::Temp module
A> move($file, $temp_file);
A> local *in;
A> local *out;
gack! use lexical filehandles. and glob handles are upper case by tradition
A> open(in, "<$temp_file");
A> open(out, ">$file");
you check for the file with -f but not here? always check your open
calls for failures
A> while(<in>) {
A> chomp;
A> s/\r$//;
why the chomp AND s///? s/[\r\n]+$// would work anywhere.
A> if ($trim eq "true") {
A> s/^\s*//;
A> s/\s*$//;
A> unless ( -z $_ ) {
huh??!! what do you think -z does? this is perl, not shell.
and if i get your logic (which is coded incorrectly), you want to not
print lines that had only blanks. that means this is not a true dos2unix
program since that is not part of the typical spec for that.
A> print out "$_\n";
A> }
A> } else {
A> print out "$_\n";
A> }
redundant code always bothers me. if you used next you could have that
one print line for both cases.
and you still top post.
A> Hm, my subroutine is actually working just fine, prove me wrong, it
A> conversts DOS files to UNIX just fine.
it still has several bugs
A> All examples given involve calling perl from code, I don't like it, I
A> would like a subroutine or function which can be included in my perl
A> code. I don't like calling perl from perl.
you never answered that question.
your skill levels demonstrate that you don't know when to call perl from
perl. so your saying you don't like it doesn't hold any water.
nevr fixed that bug.
never fixed that bug
and most of the bugs i pointed out are still there. you don't listen
well it seems.
uri