Friday, March 18, 2005

A Perl of Thoughts




Yesterday I spent my first full day coding in Perl. In the past I have done next to nothing with the language...only tinkering with a few lines here and there of existing scripts.

I would definitely say it's one of those "get-$hit-done" languages. Very little friction. I mostly related concepts back to what I knew from Python. I do think it's a language that one needs to be on their toes if they want to produce good code. "get-$shit-done" doesn't necessarily mean "write-readable-code".

Here's a few bits that I thought were neat:

Variable Interpolation

$name = "T-Bone Walker";
print "Great blues music by $name";

Prints: "Great blues music by T-Bone Walker"

That saves a lot of time especially when constructing things like HTML. It helps keep code clean by reducing concatenations.



Function with Arguments

This threw me sideways:
sub adder{
$sum = 0;
foreach $_ (@_) {
$sum += $_;
}
return $sum;
}

print add(1,2,3); # prints 6
print add(1,2,3,4,5); #prints 15
print add(1..5); # prints 15

It's unnatural to me to not declare function signatures but passing arguments as an array is an interesting concept. Lot's of flexibility.

I feel like the last person on earth learning to program with Perl but it is still exciting. I love feeling out new concepts especially with dyno-packed languages like Perl.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home