All entries for Tuesday 14 April 2009
April 14, 2009
Adventures in Perl: Part 1.
I decided recently that I'd make some effort to learn Perl. I've long been aware of it but have never found the need or inclination to use it. When I've had cause to do server side stuff for web content I've used PHP. For general *nix scripting I've coped with Bash, GNU core utils, sed and the like. On a couple of occasions recently I've found myself trying to do something which seems clumsy or just pretty much impossible in Bash etc and thought, now is the time to look at Perl. I should probably work through some sort of 'learn perl' guide at some point, I acquired a couple of O'Reilly books recently, but I'm currently taking the brute force and ignorance approach of having something I want to do and trying to do it in Perl aided by many Google searches. Some thoughts thus far:
- There is no built in function for removing trailing and leading whitespace from a string. Sure it's easy enough to do it with regular expressions, but I'm surprised there's no pre-defined function like PHP's trim().
- Lack of boolean variables. Though I'm not sure that's the right way to say it. You can't say my $blah=true or my $blah=false like you can do in JavaScript and PHP. You can use 1 or 0 though which is just as good really I guess.
- I've struggled with arrays quite a bit. Things like trying to work out how to reference the required element and how to get the contents of an array rather than a reference to it. Nothing insurmountable though and I've made it difficult by wanting to use an associative array each element of which is another associative array some elements of which are list arrays.
- I really should find out what a scalar is. I keep encountering references to them but haven't bothered to actually find out what one is.