This blog no longer exists.
You will be redirected to something cool.

Friday, August 26, 2011

Perl Heredoc & Conditionals

I just finished learning more about heredocs in Perl in my Perl programming course. After getting set up on Ubuntu, I decided to get comfortable programming in Linux again (it's a super pain in Windows.)

Here I am playing around with a few new concepts and some things (like variables/scalars) which I'm definitely comfortable and used to using. This tiny program I wrote is extremely redundant (I could write this thing to be teeny-tiny in Ruby, but I'm not at that point in Perl.) However, writing this helped me think in a more Perl-y way.

I'm using scalars, a heredoc, if statements/conditionals, and the split() function. I did this in order to write out a list of programming books in different languages and then retrieve the data with split() in order to list how many of each type of book I have. I then used an if statement to print out 'book' or 'books' based on the quantity. Quite redundant, but it works and I'll learn to make it smaller as I progress in the course.

Go ahead and check out my horrid, little program. (Yes, I know it needs a loop. I'll add it in a later update, in a later blog post :P)


This isn't horrible code for someone new to Perl. I recommend revisiting this code once you have learned about Perl arrays and again when you learn about printf and sprintf.