#!/usr/bin/perl # This will replace annoying character's with normal ones # run in Terminal by typing # perl program.pl oldfilename:newfilename # version 2, for use with an applescript :) # version 3, for handling Mac Roman characters (in addition to the plain text) # also catching MacRoman newlines (in addition to the plain text new lines) use utf8; $input = shift or die "Require original_filename:new_filename.\n"; chomp $input; $input =~ /(\S*):(\S*)/; $filename = $1; $outfile = $2; #print "$filename\n"; #print "$outfile\n"; #Things we pull out $rightquote = "\322"; $macromanrightquote = ""; $leftquote = "\323"; $macromanleftquote = ""; $apost = "\325"; $macromanapost = ""; $longdash = "\321"; $macromanlongdash = ""; $shortdash = "\320"; $macromanshortdash = ""; $l_bullet = "l "; $colon_bullet = "\; "; #Things we put in $regulardouble = "\x22"; $regularsingle = "\x27"; $regulardash = "\x2D"; $correct_bullet = "
  • "; open (OUTFILE, ">$outfile"); open (FILE, "$filename"); while ($line = ) { utf8::upgrade($line); #print $line; #$line =~ s/A/a/g; $line =~ s/$apost/$regularsingle/g; $line =~ s/$macromanapost/$regularsingle/g; $line =~ s/$rightquote/$regulardouble/g; $line =~ s/$macromanrightquote/$regulardouble/g; $line =~ s/$leftquote/$regulardouble/g; $line =~ s/$macromanleftquote/$regulardouble/g; $line =~ s/$longdash/$regulardash$regulardash/g; $line =~ s/$macromanlongdash/$regulardash$regulardash/g; $line =~ s/$shortdash/$regulardash/g; $line =~ s/$macromanshortdash/$regulardash/g; $line =~ s/^$l_bullet/$correct_bullet/g; $line =~ s/\r$l_bullet/\n$correct_bullet/g; #converts from Mac returns with bullets to Unix returns with bullets $line =~ s/\r$colon_bullet/\n$correct_bullet/g; #converts from Mac returns with bullets to Unix returns with bullets $line =~ s/\r/\n/g; #converts from Mac returns to Unix returns $line =~ s/^$colon_bullet/$correct_bullet/g; print OUTFILE $line; } close (FILE); close (OUTFILE);