I've experimented with MS Word macros, but I cannot do everything I want to easily in Word. To borrow an example from O'Reilly's Learning Python, "Suppose you need to replace any occurrence of "red pepper" or "green pepper" with "bell pepper" if and only if they occur together in a paragraph before the word "salad," but not if they are followed (with no space) by the string "corn." That's definitely way out of Word's wildcards' league." I also don't want/need Word's GUI, spell check, and all the other "overhead" in Word that eats up RAM and CPU cycles.
Based on my research, I determined that Perl is perfectly suited for the job I have. It was originally developed (1987) for text manipulation, and it is now used for a wide range of tasks. A stated design goal of Perl is to "make easy tasks easy and difficult tasks possible." Perl has been called "the duct tape of the Internet". See http://en.wikipedia.org/wiki/Perl for more info.
Perhaps the best feature of Perl is that it is relatively easy to learn -- relative to Java. However, Perl programmers love to create super-dense and terse code, and some even pride themselves on how unreadable their code can be. Terse, dense Perl code is not what I am after at this stage. I'd be happy with verbose, inelegant code - as long as it does what I want it to do.
So how does one go about learning Perl? I know from experience that it is not fun to learn a new programming language. A teacher of mine once said that it takes somewhere between 5 and 5,000 mistakes to learn how to do something (anything). If that's so, my corollary is that it takes 5 mistakes to learn a term, function or usage in a language and 5,000 mistakes, give or take an order of magnitude, to become fluent in the language, be it English, Spanish or Perl.
So the trick is to make the painful learning process interesting and enjoyable. I thought it would be fun to make a game. I call the game Blasphemy! I selected famous quotes and well-known texts and mangled them using a Perl script I wrote. Can you identify the original words and who spoke/wrote them?
- Ask for your you do ask what you; country what your can do can for not country!
- And to all that continent, nation, four men on and created are in conceived score forth a new dedicated years this seven liberty, the equal. Fathers proposition our brought ago
- Slings nobler 'tis arrows against outrageous and sea the by and that to be-- of be, to of the or question: opposing to them. Not to whether in or mind take arms troubles a end suffer is the fortune
- Heaven. Temptation, in kingdom give us forgive from is be those art and deliver thy as the father, and thy for against us come. Trespass into in for thine is hallowed the our and it forgive the who us and evil. Not glory, ever. Day done, daily on this and but we name. Who earth as will be ever us. Trespasses, our lead power, us bread. Kingdom, thy heaven, our
- Village, snow. Not house up will though; in is these his think his to whose woods here the know. See I watch woods me I He fill are stopping with
Think the little queer darkest evening year. The between of lake a and frozen without it near must the woods farmhouse to horse my stop
Bells his the sleep. Downy I is deep, to the and flake. And miles have dark, before easy I he ask woods before and mistake. Go only to harness if are miles sound's keep, sweep some gives to of promises other there but sleep, wind I the and go shake to a lovely,
So, how did you do? Want to know the answers? Here they are:
- President John F. Kennedy's Inaugural Address, "Ask not what your country can do for you; ask what you can do for your country!"
- President Abraham Lincoln's Gettysburg Address, "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal."
- William Shakespeare, Hamlet's soliloquy, "To be, or not to be-- that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune or to take arms against a sea of troubles and by opposing end them."
- The Lord's Prayer. "Our Father, who art in heaven, hallowed be thy Name. Thy kingdom come. Thy will be done, on earth as it is in heaven. Give us this day our daily bread. And forgive us our trespasses, as we forgive those who trespass against us. And lead us not into temptation, but deliver us from evil. For thine is the kingdom, and the power, and the glory, for ever and ever."
- "Stopping By Woods on a Snowy Evening" by Robert Frost.
Whose woods these are I think I know.
His house is in the village, though;
He will not see me stopping here
To watch his woods fill up with snow.
My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.
He gives his harness bells a shake
To ask if there is some mistake.
The only other sound's the sweep
Of easy wind and downy flake.
The woods are lovely, dark, and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.
1 comment:
Well, some people who program in Perl might pride themselves on terse and unreadable code, but those aren't the people you care about or who are going to get in your way of using Perl. :)
Post a Comment