Home: Perl Programming Help: Beginner:
number of characters in string?



emelin
stranger

Mar 6, 2001, 7:26 AM


Views: 323
number of characters in string?

How do I count the number of characters in a string and then do stuff depending on the number?

I want to do something like:

if number_of_chars_in_$text > 200 {
print char1-char200_of_$text;
print "<a href=allofstring.cgi>cont</a>";
}else{
print $text;
}

(I am reading news items from a file and if the item is too long I want to print out only the first few lines and then link to the entire news item)





japhy
Enthusiast

Mar 6, 2001, 1:19 PM


Views: 321
Re: number of characters in string?

length()

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


emelin
stranger

Mar 7, 2001, 2:34 AM


Views: 313
Re: number of characters in string?

Thanks, great..!

Now, how do I print out the first, let's say, 300 characters of the string $text???



Jasmine
Administrator / Moderator

Mar 8, 2001, 8:55 AM


Views: 306
Re: number of characters in string?


Code
print substr( $text, 0, 300 );