Perl
If you need to XML, Learn Perl
You will be typing a lot of repetitive lines. A simple for(n..q) construct can save you a lot of time.
XML will require you to write many, many lines that look 99% the same
... <key> filenames </key> <array> <string> 00.gif</string> <string> 01.gif</string> ... <string> _n_.gif</string> </array> The ability to have something spit out that n-many lines is very handy.
BTW. I’m re-adding all the other pages previously known in the previous incarnation of the site.
Please tolerate some ugly pages.
Perl coding in the enterprise considered Harmful
It’s true, if ever you’ve had to debug someone else’s Perl code it’s …. daunting, irritating, despondence-inducing, isolating, baffling, frustrating.
Perl is a great language wherewith to get something done and forget it.
“I need to slurp all the pics of Marilyn on this site” “I need to edit one line in 30 files”
Perl is your buddy.
If you have to come back to this or a task later, this flexibility and permissiveness will make even your own code seem….beyond easy comprehension. Granted one can leave some breadcrumbs to make this process easier…yet still it’s inherently Not Easy (tm).
Programmers and domestic goddesses
#!/usr/local/bin/perl print "aww\n" I wrote a suite of Perl programs to generate all the quilt blocks of a certain type: sixteen “half-square triangle” patches arranged into a square with 90-degree rotational symmetry, and printed out the result
I was even more delighted when the quilter and I got married. She made the program output into a real quilt and gave it to me as a wedding present. There are pictures here.
Cuteness
A Handy Tip for Ruby Developers: Dispatch Tables
If you are learning Ruby coming from a C or Perl background, you may find the following discussion somewhat interesting.
One of the most common idioms ( especially in my CGI programming in Perl ) is to use a dispatch table based on a keyword or an option.
It is particularly handy to arrange a hash such that by entering a ‘keyword’ (the key in the hash element) you trigger an anonymous subroutine, or a pre-defined routine.
The code for this, in Perl, looks something like this:
my %h = ( 'alpha' => &theAlphaRoutine;, 'beta' => &theBetaRoutine;, 'gamma' => &theGammaRoutine;, );
How I write Perl
When I write Perl, on my own, it looks like the following. This is Perl written in the “functional” style I advocate.
The code takes a listing of simple definitions:
tree noun something organic with leaves
and turns it into LaTeX Beamer–class slide markup.
\frame{
\frametitle{tree }
\begin{itemize}
\item tree
\pause
\item noun
\pause
\item
something organic with leaves
\end{itemize}
}
When the Beamer LaTeX code is complied with pdflatex it produces a slide show.
You can see how something like this is handy for someone studying their GRE Vocabulary builder. Code after the jump.
Perl things I always forget
This idiom, I love it so much but I use it fairly infrequently, but it’s absolutely gorgeous
# Assign to another variable the result of a RegEx ($new= $old) =~ s|foo|bar|g; And this one I just forget, because I tend to use hashes
# Remove element from an array based on index: splice(@array, 3, 1);
Benefits of "Functional Perl": ease of modification
In an earlier post I provided code demonstrating my “functional” Perl idiom. The purpose of that code was to take a very simply formatted text file and to turn it into LaTeX Beamer formatting.
Well, recently I found the application iFlipr. In addition to being a site where you can upload flash cards, it also has an iTouch / iPhone version so that you can review when you’re in the bus, in a waiting room, etc.
So, I needed some code to transform my generic data set into–not LaTex–but iFlipr format. With but the most trivial of changes, I was able to accomplish this.