Gossamer Forum
Home : General : Perl Programming :

How to...chop $rec{'Description'}

Quote Reply
How to...chop $rec{'Description'}
Hi,

I am trying to figure out how I can shorten the length value returned by $rec{'Description'} in Links. This being more of perl cgi question, I thought I'd post it here.

My descriptions can be upto 3000 characters, but I want to only print say the first 150 characters to the html page...

I've tried to find a reference to doing something like this in my book, but I can't find anything similar, surprisingly!

Your thoughts and ideas will be very welcome...Thanks

Rod
Quote Reply
Re: How to...chop $rec{'Description'} In reply to
Hi,

(length $rec{'Description'} > 150) and ($rec{'Description'} = substr $rec{'Description'}, 150);

will do the trick. It checks to see if the the description is > 150 characters, if so, it chops it to 150 only.

Cheers,

Alex
Quote Reply
Re: How to...chop $rec{'Description'} In reply to
Alex,

It works but it prints out the Last 150 characters...how could I change it to print the First 150?

Much Appreciated
Rod
Quote Reply
Re: How to...chop $rec{'Description'} In reply to
No worries,

I got it:

(length $rec{'Description'} > 100) and ($rec{'Description'} = substr($rec{'Description'}, Smile0, 100));

Just needed to set the OFFSET to start at the first char

Thanks
Rod

[This message has been edited by phoule (edited April 06, 1999).]