CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substitution

 



Saya
Novice

Jul 4, 2002, 1:11 AM

Post #1 of 2 (306 views)
substitution Can't Post

Hi,

I have the following scenario. I have a string on which I have to perform the following: if the string length is > 16 then I have to insert break the string into 2 chunks, obviously the first string containing the 16 characters. Now on this I need furhther procession. If these sixteen characters contain an '_' (underscore) then rigth after the '_' i need to add the following to the string '$#xA0;' (non breaking space), otherwise enter the code a line break at the first non breaking space from the rigth hand side. Can anyone quickly scrabmle that code in perl ???


davorg
Thaumaturge / Moderator

Jul 4, 2002, 2:16 AM

Post #2 of 2 (303 views)
Re: [Saya] substitution [In reply to] Can't Post

Something like this I guess (assuming your text is in $string)

Code
my ($first, $second); 

$first = $string;
$first = substr($string, 0, 16) if length($first) > 16;

unless ($first =~ s/_/_\$#xA0;/) {
$first =~ s/ /\n/;
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives