Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Replace a word in a line except for the last char of the word?

by perlsen (Chaplain)
on Mar 11, 2005 at 12:58 UTC ( [id://438630]=note: print w/replies, xml ) Need Help??


in reply to Replace a word in a line except for the last char of the word?

Hi, just try the below code (is this meet your requirement?)

my $line = '<br> 2<br> 3<br> 4'; my $temp = $line; while ($temp =~m#(<br>)(.+?)( \d+)#gsi) { my $full= $&; my $text=$1; my $space = "$2"; my $digit = "$3"; my @arr=(); (@arr) = $space =~s#( )# #gsi; my $nbsptext = "&nbsp;" x "@arr"; $line =~s#$full#${text}${nbsptext}${digit}#gsi; $full=""; } print $line; output: <br>&nbsp; 2<br>&nbsp;&nbsp; 3<br>&nbsp;&nbsp; 4
  • Comment on Re: Replace a word in a line except for the last char of the word?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://438630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found