Find unbalanced smart quotes in HTML using Perl

So I’m brushing up an HTML document so I can publish it on the Kindle and I’ve discovered lots of unbalanced smart quotes. Smart quotes are double quotes that face to the right or the left, rather than just straight up and down. In HTML, they are rendered as “ldquo” and “rdquo” with an ampersand in front of each and a trailing semi-colon. I wrote a little script to make sure that for every left side I had a right side, and print out the lines in which they do not match.

Here you go:

#!/usr/bin/perl

open(FILE,"./file.html") or die "Can't open file.html: $!\n";

while(<FILE>) {
   chomp();
   $line = "$_";

   $l = "ldquo";
   $r = "rdquo";   
   $lc = 0;
   $rc = 0;   

   $lc = () = $line =~ /$l/g;
   $rc = () = $line =~ /$r/g;

   print "Lc = $lc  Rc = $rc\n";
   if ($lc != $rc) {
      print "\n$line\n";
   }
}
close(FILE);

3 Comments

Filed under Grammar/Punctuation, Tools for Writers

Editing

Doing a lot of editing these days.  Ugh, I hate it.  First I mark it up, then I go through and put in the changes.  Only it isn’t that easy, is it?  I also have to evaluate the proposed changes and decide if they are good or if I was smoking crack or something that day.  Work work work.

Neat editing blog I found today:

http://deareditor.com/

2 Comments

Filed under Uncategorized

Added another link to my Editing Blogs collection

Terribly Write

Leave a comment

Filed under Grammar/Punctuation

Great book I found on bad writing

In my experience, books on writing haven’t been that useful to me. The ones I’ve read make a big deal about stories having a beginning, middle and end. Or they tell you things like “write every day” or “write what you know” or “use active voice.” Timeless advice found in any book on writing, but nothing new. Stephen King’s book was good, but mostly because I was interested in Stephen King. He had a few good tips in there, especially on editing out things like “that” and what not.

Yesterday, I stumbled upon a great book recommendation at my favorite editor’s blog (the Editor’s Blog). It’s called, “How not to write a novel.” In it, the authors go over all the things they hate to see in submitted works by the unpublished masses (like me). Not only don’t they pull punches, but they actively ridicule anyone who makes these mistakes (without naming names). It’s actually pretty funny. Just this morning, I got caught off guard by the observation that some writers dredge up vocabulary from “the darkest regions of the dictionary.” This caused me to snort, which caused my hand to jiggle, sending coffee dribbles spilling onto my shirt.

I’ve read about 2/3 since yesterday and I have to say: I’ve done many of the things they’re talking about, at one time or another. Recently, I committed the crime of writing what they call a “benign tumor.” A benign tumor, according to the authors, is when you write a scene that extends the book, but if you cut it out, absolutely nothing happens to the story. Imagine the good guy going to kill the villain and taking 5 pages to talk about a detour he was forced to take through a nice part of town, musing how after he kills the villain maybe he’d move there. Benign tumor.

Enjoy.

2 Comments

Filed under Publisher's Advice, Submission Tips, Writing in general

When you can’t write something nice…

So my wife and I went to New York to see a show and spend some quality time together. On a lark, we decided to visit Guy’s American Kitchen & Bar, since we loved how viciously it had been savaged by Pete Wells in his now infamous review.

My initial reaction to the review was wow, this is awesome. A small, mean part of me thought, “That’s what this TV person gets for whatever!” Another part of me wondered: how can everything about this famous restaurant be so completely awful? Though I enjoyed the review, I smelled a rat. So when I got to New York, I simply had to go there. Now, I’m not a food critic, nor a chef, but I’ll tell you: the food knocked my socks off. My wife ordered the Acapulco Gold salad and I got the General Tso’s Pork Shank. I had some of her salad: delicious. My pork shank was tender, tasty, and I wanted more when I was done. Desert was great as well (Salted Whiskey Caramel Fool). Afterward, walking around Times Square, I didn’t think to myself, “Boy I wish I hadn’t eaten that.” I felt satisfied and glad I’d gone there. Which made me wonder all over again: was that review just a major hit piece? Did it have anything to do with the food or had it been all about the writer?

Update:
I’m reading through the comments on the review, and it’s amazing how many people are bashing the restaurant. Many are saying they’ve been there and didn’t like it. For those who actually went there and didn’t like it, I wonder if they hated it like the reviewer, or simply thought “oh, I’m full now” and went home. Another thing about the comments: it seems like many of them are trying to outdo the reviewer in their viciousness. I wonder if these same, sophisticated commentators stopped drinking Merlot after watching the movie Sideways.

Leave a comment

Filed under Writing in general

Meet my dog, Peekabu

Ok, so I have nothing to post about. My wife has my Macbook Air and will have it for the next month or so, and I hate writing on anything OTHER than my Macbook Air, so I’m not doing any writing. This sorry excuse will only last so long. I hope to begin the next project soon. Meanwhile, meet Peekabu, my Old English Sheepdog!
peekabu

Leave a comment

Filed under Writing Experience

Have been out of town – journaling

I’ve been visiting family in Arizona so I haven’t been on much nor doing any writing. To make up for my lack of productivity, I’ve been vigorously writing down anything anyone says that’s funny or interesting, with the hopes of one day using it in a story and pretending I came up with it. Ok, kidding on that last part (maybe).

Leave a comment

Filed under Legal / Safety

Great interview with Jim Butcher

I just read a wonderful interview with Jim Butcher (my favorite fantasy writer).  A good takeaway is when he starts talking about the importance of outlining in his novels.  I outline, a little, and reading this makes me want to take it more seriously.

Jim Butcher Interview

Leave a comment

Filed under Writing Experience

Excellent writing site for daily tips

I only subscribe to two twitter feeds:  Jim Butcher’s, though he doesn’t tweet much, and Daily Writing Tips.  But you can go to the website and see all the great tips.  Normally, it’s sort of like Grammer Girl with larger lung capacity. But occasionally you’ll see stuff related to crafting, like his article: Let the Words Do the Work.

 

2 Comments

Filed under Uncategorized

Preliminary homophone finder written in perl

I wrote this little perl script to find homophones in text documents, so if you save your word doc as a text file, in theory you can find all the homophones with it.  I’m using 943 homophones and running the first part of a Winston Churchill speech through it 🙂

To run the script, you’d need to know a little perl and how to use it. So for most people, this isn’t particularly user-friendly.  It’s more for fun, as well as a proof of concept on a hypothetical tool writers could use to keep silly mistakes out of their writing.  While the script runs, you hit ‘enter’ occasionally to go to the next line with one or more homophones in it.

The script needs:

  • words.txt – a list of homophones one after the other  (it makes sense to edit out of this any words you’d never mess up, for example, “I” vs. “eye” or “were” vs. “whirr”)
  • ms.txt –  your manuscript saved as a text file

First, the code:

#!/usr/bin/perl

open(WORDS,"words.txt") or die "Can't open words.txt: $!\n";
@words = <WORDS> ;
close(WORDS);

open(MS,"ms.txt") or die "Can't open ms.txt: $!\n";

while(<MS>) {
   chomp();
   $aline = $_;
   lc($aline);
   $match = 0;
   foreach $i (@words) {
        chomp($i);
      if ($aline=~/\s+$i\s+/g) {
        $match = 1;
        $uppercase = uc($i);
         $aline=~s/\s+$i\s+/ \*$uppercase\* /g;
      }
   }

   if ($match == 1) {
      print "$aline\n";
      print "[ hit enter to continue ]\n";
      $ans= <> ;
   }
}
close(MS);

Here’s what happens to the first part of this famous speech:

I spoke the other day of the colossal military disaster *WHICH* occurred when the French High Command failed *TO* withdraw the northern Armies from Belgium at the moment when they *KNEW* that the French front was decisively broken at Sedan and on the Meuse. This delay entailed the loss of fifteen *OR* sixteen French divisions and *THREW* out of action *FOR* the critical period the whole of the British Expeditionary Force. Our Army and 120,000 French troops *WERE* indeed rescued *BY* the British Navy from Dunkirk *BUT* only with the loss of *THEIR* cannon, vehicles and modern equipment. This loss inevitably took *SOME* weeks *TO* repair, and *IN* the first *TWO* of those weeks the battle *IN* France has *BEEN* lost. When *WE* consider the heroic resistance *MADE* *BY* the French Army against heavy odds *IN* this battle, the enormous losses inflicted upon the enemy and the evident exhaustion of the enemy, it may well *BE* the thought that these 25 divisions of the best-trained and best-equipped troops *MIGHT* have turned the scale. However, General Weygand had *TO* fight without them. Only three British divisions *OR* *THEIR* equivalent *WERE* able *TO* stand *IN* the line with *THEIR* French comrades. They have suffered severely, *BUT* they have *FOUGHT* well. We *SENT* every man *WE* could *TO* France as fast as *WE* could re-equip and transport *THEIR* formations.
[ hit enter to continue ]

I am *NOT* reciting these facts *FOR* the purpose of recrimination. That *I* judge *TO* *BE* utterly futile and even harmful. We cannot afford it. *I* recite them *IN* order *TO* explain why it was *WE* did *NOT* have, as *WE* could have had, between twelve and fourteen British divisions fighting *IN* the line *IN* this *GREAT* battle instead of only three. Now *I* put *ALL* this aside. *I* put it on the shelf, from *WHICH* the historians, when they have time, will select *THEIR* documents *TO* tell *THEIR* stories. We have *TO* think of the future and *NOT* of the past. This also applies *IN* a small *WAY* *TO* *OUR* own affairs at home. There are many who *WOULD* hold an inquest *IN* the House of Commons on the conduct of the Governments-and of Parliaments, *FOR* they are *IN* it, too-during the years *WHICH* *LED* up *TO* this catastrophe. They seek *TO* *INDICT* those who *WERE* responsible *FOR* the guidance of *OUR* affairs. This also *WOULD* *BE* a foolish and pernicious process. There are *TOO* many *IN* it. Let each man search his conscience and search his speeches. *I* frequently search mine.
[ hit enter to continue ]

Leave a comment

Filed under Grammar/Punctuation, Tools for Writers