Blog This!   Lee Geistlinger's Web Log
Blog Home
Blog Archives
LittleGhost Home

E-mail: geistlinger AT gmail.com

Loading
Pic 'O the Day
Top 10 Lists
Everyone loves lists
Reviews
Books, Movies and so on
Blogroll
Feed Me!

XML Feed

Feeds I Read

My Online Aggregator

Theme
• Default
• Spring
• Summer
• Autumn
• Winter
• Black & White
• Gray & White
• MT-ish
• Classic
Listening To...
Evidence of Efforts

This page is powered by Blogger. Isn't yours?

Valid CSS!

[Valid RSS]

Recent Posts
 Monday, May 03, 2004
Perl Gripes

WATCHING:
Big Fish
It took me awhile to warm to this movie, but I ended up enjoying it.

Not a great movie, not one I'll watch again for some time, but with a sweet, funny and thoughtful story line. And great imagination.

Actually, this is a movie that works better as a preview - it's got some great, three-second-long shots that would translate well to previews/commercials and so on.

All movies

There's a lot of iffy areas that Perl catches flack for - loosely typed variables, overuse of hashes, the utter incomprehensibility of some excellent code (such as a great regex to extract data - looks like a punctuation-fest).

However, my biggest gripe - and maybe I'm missing something - is the lack of a built in trim() function.

Why not??

While I understand that you can use a regex like I have above, a trim function is something, to me, that should be part of every language.

Especially in these days of XML and Web-based apps, the spaces can matter.

So you want to trim stuff before it goes into the database.

Ditto when it comes out.

But that's me.


=======
PHP
=======
$myVar = " Foo Bar ";
$myVar = trim($myVar); // now "Foo Bar"; full trim
$myVar = ltrim($myVar); // now "Foo Bar "; left trim
$myVar = rtrim($myVar); // now " Foo Bar"; right trim

=======
T-SQL (MS SQL Server)
=======
-- No full trim (makes me nuts, also!);
-- nest left and right trims
select ltrim(rtrim(' Foo Bar ')) as myVar;
-- will return "Foo Bar" for myVar

======
Perl
======
$myVar = " Foo Bar ";
$myVar =~ s/^\s+|\s+$/; # returns "Foo Bar"


There is an int() function in Perl - that returns a string as an integer. You could write a simple regex for this, as well, but there is the more useful - and expected - int function (parseInt() in JavaScript, I believe - in database languages you often have to CAST the string).

So why not a freakin' trim function?!?

I still like Perl in spite of it.

- Posted by Lee at 9:29 AM Permalink #
^Top | Top Ten Home | Blog This! Home | Blog This! Archives