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


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
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