I’ve been reading the classic book on memorization, The Memory Book, and it’s really a complete memorization system. By associating new ideas with something you already know in a ridiculous way, you can memorize massive amounts of information at once.
We’ll start by memorizing the classically difficult to remember (and understand) regular expressions in Perl.
For those of you that don’t know, regular expressions allow us to do cool stuff with strings like change capitalization with a single line of code.
=~
This is the equals tilde character. It takes a string and searches through it to see if it has what we’re looking for. To remember this we could break down “equals tilde” into something that sounds similar. Ecstasy quells tiles (E-quells tiles). Imagine a bunch of tiles at a rave taking ecstasy. They’re all searching for something true. The meaning of life, maybe. Either way they’re searching for some sort of truth.
$mylife =~ m/so cool/;
!~
Not tilde. Same as =~, except returns true if the expression doesn’t match. Imagine a bunch of naughty tiles who hate ravers. They don’t think we should search for truths, but rather search for falsehoods.
$life !~ m/meaningful/;
/
Slash. The delimiter in expressions. Easy to remember. Just imagine cutting the expression with a butter knife.
$forrestgump =~ m/Bubba/;
m
“m”, the match operator. Returns true if there’s a match in the expression to the immediate right of it. Just think of m as being a highly paid matchmaker living in Manhattan with a million dollar loft.
$matchmaker =~ /match/;
^
Carat, the beginning of a new line character. If it’s found between the slashes, it means we’re looking for a new line. Just imagine Elmer Fudd holding a carat on a fishing line over Bug’s home
$joke =~ m/^Not funny/;
$The end of line character. Think of money as being the end of all life. Example:
$money =~ m/the end$/;
i
The case insensitivity character. I am insensitive to avocado farmers. Example:
$strung =~ m/mYSpaCe/i; # returns true if the idiot wrote Myspace in weird caps
tr
The translate character. Takes one character and replaces it with another. Think of a drunk, one armed Tony Robbins translator to remember it. He sure is a character.
$sweet =~ tr/[a-z]/[A-Z]; # replace lower case characters with upper
s
Substitute string. Substitutes an entire string with another. Simon says substitute.
$president =~ s/George Bush/Reptoid/; # Replaces the president with a reptoid
[]
Brackets, organize by character classes. Takes in and searches character by character. Think of an actor breaking out of character and crying because his trailer is dirty. Usage:
$sweet =~ tr/[a-z]/[A-Z]/;
That’s it for part one. On to part two, where we learn about wild cards.