[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Porting MacPerl to Unix



It might well be due to the carriage return/line feed problem...
here's a script that might be helpful for you...
just drop a directory onto it and it converts Mac end of line
characters to Unix ones.  Works recursively, etc.

BE CAREFUL -- it will destroy binary files.  It's not
guaranteed for any purpose.  Always back your code up.
etc.etc.etc.

Here's the source...

#!/usr/bin/perl
#
# convert ^M to ^J
#
use File::Find;

while ($_ = shift @ARGV) {
   if (-d $_ ) {
     find( \&sublf, $_ );  # apply this function to all files in this
directory.
   } else {
     sublf( $_ );        # just do this to the file
   }
}

# make all line feeds into carriage returns.
#
sub sublf () {
  return if (-d $_);
  print "Processing $_";
  open( ARG, $_ ) or die "Can't open $_; leaving!";
  my @lines = <ARG>;
  close ARG;

  my $found = 0;
  open( ARG, ">$_" ) or warn "Can't open $_ (2)";
  foreach (@lines) {
    $found = ($_ =~ s/\n/\r/) || $found;
    print ARG $_;
  }
  print "... no changes made" if not $found;
  print "\n";
  close ARG;
}

Attachment converted: mouse1:unmac (eApp/CSOm) (000040CF)