On 05/04/2011 22:56, Paul Johnson wrote:
On Tue, Apr 05, 2011 at 04:25:12PM -0500, Matt wrote:
I am looking for a perl function or easy way to shorten a long string
if its over X characters.
Say I have:
"Doe, John; 56943 Walnut Drive; SomeCity, NY"
It messes up the display of my html form. So I would like it changed to:
"Doe, John; ..... meCity, NY"
Keep first 10 and last 10 characters and abbreviate all else.
The function you are looking for is substr.
$ perldoc -f substr
You probably want something like:
substr $x, 10, -10, " ... " if length $x> 25;
Very neat Paul. My hat's off to you.
Rob
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/