Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

  (email not shown publicly)
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Monday July 23, 2007
05:16 PM

string truncate: now with word boundaries

[ #33868 ]

Since roughly forever ago, I've meant to give String::Truncate the ability to try to truncate a string at word boundary. Done! That is, instead of turning "This is your brain on drugs." into "This is your br..." it can now return "This is your...".

This is one of those cases where my desire for the feature wasn't quite sufficient to get me to implement it. Sure, I wanted it now and then, but I didn't feel like writing tests or code for it. In these cases, what usually motivates me is pride: I find some other code that does what I want, but is otherwise inferior or, equally likely, just bugs me in its interface.

It turns out that this feature took no time at all -- not surprisingly, I guess. What I like about String::Truncate is that it focuses on making the not-quite-simple cases as easy as the simple ones, so that I can do what I really want, not just what's easy, without having to care. I need to write more code like that.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.