Substitute and replace

F

francan

I have the below examples where I need to get the lastname using Perl
substitute and replace:
joeAAAAsmith jrAAAAbudget where I need to get smith jr
or this
GeneAAAAEvansAAAAmanager where I need to get Evans

I need to fetch just the lastname which will always be in between the
AAAA and AAAA delimeter: SteveAAAAJones-SingletonAAAAengineer where I
would need to get Jones-Singleton

I used the below and it worked but would like to know if this is the
most efficient way to do it?


s/(.*)AAAA(.*)AAAA(.*)/$2
 
J

Jürgen Exner

francan said:
I have the below examples where I need to get the lastname using Perl
substitute and replace:
joeAAAAsmith jrAAAAbudget where I need to get smith jr
or this
GeneAAAAEvansAAAAmanager where I need to get Evans

I need to fetch just the lastname which will always be in between the
AAAA and AAAA delimeter: SteveAAAAJones-SingletonAAAAengineer where I
would need to get Jones-Singleton

I used the below and it worked but would like to know if this is the
most efficient way to do it?


s/(.*)AAAA(.*)AAAA(.*)/$2

Remember the old rule of thumb: if you know what to keep use s///, is
you know what to throw away use split():

$lastname = (split /AAAA/, $foo)[1];

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top