Gossamer Forum
Home : General : Perl Programming :

test and replace the last letter of a chain

Quote Reply
test and replace the last letter of a chain
Hi

I have many lines in one of my table as follow :

1 aayaadaax
2 bbybbbbbbbby
3 yccz

I want to displays these lines in my page but if the last letter of the chain is a "y" I want ot replace it by a "m"

So for my tree lines it should be

aayaadaax (nothing to do)
bbybbbbbbbbm (the last letter was a "y" so I did relpace it by a "m"
yccz (nothing to do)

I would like to know the perl command in perl to do it

Do I have to make a reverse of the chain and replace the first letter if it is a y then to make another reverse to display the chain

Txs for your help

FMP

Quote Reply
Re: [fmp] test and replace the last letter of a chain In reply to
Something like;

$var =~ s,y$,m$,;

Unsure

cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [fmp] test and replace the last letter of a chain In reply to
Easier to do it from the command line :)

Code:
perl -p -i.bak -e 's/y$/m/' your_file.html

Last edited by:

Paul: Jun 8, 2003, 4:55 PM
Quote Reply
Re: [Paul] test and replace the last letter of a chain In reply to
txs for u2

it works great

FMPWink