How about

use constant MAXSTRLENGTH => 4096;

substr($string, MAXSTRLENGTH - 1, -1) = '' unless(length($strlen) <
MAXSTRLENGTH);

On 21 Jun 2001 11:31:21 -0700, Chuck Ivy wrote:
> I've got a simple message board script that I cobbled together. It seems 
> to have been the target of some abuse, though.
> 
> The latest patch I'd like to apply to the code would be limiting the 
> length of a message posted to, say, 4096 characters.
> 
> Now, looking up the substring function, it looks like if the original 
> string were less than the size of my substring, it would pad my variable 
> until it was 4096 characters.
> 
> Would a regex be better? Matching for up to 4096 characters and 
> replacing the string with $1?
> 
> I recall some programming languages treat strings as arrays of 
> characters. Is there a quick perl function or variable that represents 
> the length of a string? I didn't see any obvious entries in the index of 
> Programming Perl, but I may have been looking in the wrong place.
> 
> Or is this a good place for formatting commands?
> 
> Any suggestions welcome.
> 
--
Today is Boomtime, the 26th day of Confusion in the YOLD 3167
Keep the Lasagna flying!


Reply via email to