My Perl and Ruby Story

I’m not old enough to have grown attached to Perl. When I learned Perl people were already looking at Ruby and Python and proclaiming glorious victories. At that same time I saw people gripping Perl, not willing to leave their witty, terse confidant for those prettier, risky “New Kids on the Block.” I had dabbled with PHP and wanted more power. Perl was the natural choice. Previous experience, I thought, told me that I wanted a programming language where symbols, not words, held power. I quickly saw that in Perl. There were scripts nearly 50% symbols performing enticing feats with less characters then a Java Hello World program. So I took a look at Perl.

Summer Dreams Ripped at the Seams

As is the case with most Perl programmers I felt right at home. Perl has a tendency to do whatever you, the programmer, want’s it to do. “Do you want to suddenly make this variable in the middle of an if statement’s condition? Sure, why not, you’re the boss!” I instantly fell in love with its regular expression support. Learning to exploit the s/// statement alone has probably had far more impact on my entire programming career then any college course I’ve taken. The idea of a default variable was a poison I was happy to swallow. It just made so much sense.

# A Perl Script I wrote... Usage is not important
while (<>) {
   print "n$1: $2n" if /(.*?)s*w+ d+, (d+:d+)s*$/;
   print if ! /s*d+:d+s*$/;
}

My interest in Perl stopped when I saw its Object Oriented behavior. However, by that time I was far more interested in its scripting power. I took a very close look at Perl’s syntax and grammar. I knew every optional space… every optional semicolon… how to reduce an entire program to a single line and then reduce it further and further with dirty tricks. I ate up as many of Perl’s special variables as I could, spitting them out into my scripts. Why write “n” when $/ is two less characters… Essentially I learned to “Perl Golf.” It is the art of dwindling a simple script program down to as few characters as possible. This “black magic” side of Perl that got criticized by so many was a dangerous, but fun, sandbox that I spent my time in. Then, it all stopped.

$_=chr 123*rand,/[da-z]/i?$a.=$_:redo for 1..pop;print$a,$/

Normally, whenever I had a few weeks I would spend them learning a new programming language for fun. When I learned Perl I had three weeks off from school before I was to start my first Co-op. Time flew and my “fling” with Perl had to end. Little did I know that Perl left a rash on me that needed to be scratched. This disease made other programming languages look disgusting. Why is it so hard to parse files in Java, why is there no built-in regular expressions support in C++, what is wrong with these languages?!

A New Direction

Time went on. I was given another two weeks. Around that time I had made a decision that I would invest my personal time into web development. I spent hours and hours reading, learning, experimenting, grasping, producing, and all that jazz. It was reaching the end of those two weeks and one thing had been continually pounded into my head… Ruby on Rails was going to be big. I was young, I wanted in! With little time left in those two weeks I figured my time would be best spent focusing on Ruby and investing in Rails when I got more time. I honestly haven’t gotten around to learning Rails yet because I was so enamored with Ruby.

Learning Ruby was initially painful. I’ll admit it. I took a pass at it and was disgusted. To be honest, I can’t remember what was so painful. For one, I was intimidated by its block structure. Being as immature as I was, it felt too verbose… like a sore thumb in the language. But what the hell did I know? I still gave it a shot.

Why's Poignant Guide To Ruby

This book had a greater impact on me then just teaching me Ruby. It reaffirmed what I had seen from all over the web. Ruby users had a sense of humor, they tended toward creative expressiveness instead of technical explicitness, they invested in fun, they were not satisfied with the mundane. Also, the idea that a tutorial could be a story changed the way I thought about teaching in general. I made it far enough to drop my misapprehensions about Ruby’s syntax and embrace something Ruby did well at, Objects.

Perl Replacement

The more I used Ruby the more I realized that I wouldn’t need Perl. All my special variables were there. Replacing s/// with gsub was painful, but undeniably cleaner. I had matured slightly as a programmer and saw the need for code clarity and I now enjoyed Ruby’s block structure. When I challenged myself to create a simple Object Oriented program I saw how Ruby’s classes removed a lot of the repetition I normally put into Java classes. I was pleased.

I have to mention irb, Ruby’s interactive interpreter. This tool has proven invaluable to me. I almost always have an irb prompt open at all times. It is my calculator, my hacking companion, my playground, a debugger, and a friend. Perl lacks such an environment. I’ve had to really work to get the perlconsole working and Perl’s debug REPL just isn’t nearly the same. I’ve been able to expand and customize irb into an indispensable tool that can help me on any project. I think thats important, because with my Generation-X attention span, being able to copy.paste.sort.filter.reorder any text at a moments notice is “clutch.”

irb

Finally I was impressed with ruby gems. Need an html/xml parsing library and you’re unhappy with Ruby’s? Fine, `gem install hpricot`. Its so easy to download a new library, or even a new tool like `gem install cheat`. I liked the idea of distributing ruby scripts via gems that I even made my script a ruby gem (regex_replace). That way I can quickly download/install on any machine that I need it. The ability to build off of existing Ruby libraries is exciting.

The Beginning

As clich├ęd as that sounds, I feel like it can only get better. I’ve gotten comfortable enough with Ruby that I now write all my day-to-day scripts in it. I’m truly glad that I learned Perl, because it introduced me to the scripting world, and it is a unix staple. But, like so many others, it seems like there is a brighter path. I think thats more then enough for today.

Cheers.

Add a Comment

search