Learning Perl
I'm learning Perl right now and I gotta say, there's something awesome about Perl. I've meaning to learn it for a long time and now that I am, it is awesome. I have read how Perl is one huge hack and I agree. (Now I'm entering into a rant mode where I explain its awesomeness with code. Personally, when I read others, it's interesting but doesn't really apply to me. So this post is just dedicated for me and all those guys who always disagree)
They say Perl is made by a linguist. I can see why. Look at Perl vs Python. In Python, when you want to multiply strings and letters, it goes like this:
print "fred" * 3
Amazingly, in Perl it's an error and returns 0
.
print $fred x 3
Yes, you need a x
and not *
.
Talking about variables, Python vs Perl
print "I ate a %s" % steak
print "I ate a $steak"
The fact that you need to use "" and not '' to invoke variables in strings is awesome and somehow semantically clean.
Calling functions is also really neat. I like the fact that you don't need to use ()
for most. I also like how you declare them - arguments aren't declared in the function like Python:
def fark(you): # really annoying compared to sub fark { my fark }
I'm not done with Perl yet but I'm really enjoying it so far. Of course, I'm not a veteran yet so I won't understand all those nightmares of hacked Perl. Until then ~ pandaox
Written by pandaox
Related protips
2 Responses
Talking about single and double quotes, I think this behavior was inherited from the Unix shell, which has the same behavior. Try:
echo 'Non-interpolable: $X' "Interpolable: $X"
Talking about string formatting operations in Python (modulo). Python documentation of modulo reffers to sprintf() syntax in the C language. Perl also has printf() implementation:
printf "I ate a %s", $steak;
And I hope you'll enjoy learning Perl and using it in your projects. Good luck.
@yko thanks for stopping by and reading my post. I usually roam around in my little corner and I'm quite surprised that someone did read it. By the way, I've seen your Perl code and I am impressed. Perl does seem like a beautiful language and I hope to use for real someday.