[LA.pm] how do I trim a $var down

Mike Dillon md5 at embody.org
Fri Jun 24 22:43:01 PDT 2005


begin David Heayn quotation:
> I came up with this line out of the camel book...
> 
> substr($content, 101) = "";
> 
> 
> 
> but I get an error:
> 
> substr outside of string at cgi-bin/blog.cgi line 38.
> 
> 
> I'm missing something.

You only should do it if the string is actually longer than 100:

    substr($content, 101) = "" if length $content > 100;

-md


More information about the Losangeles-pm mailing list