Link to home
Start Free TrialLog in
Avatar of n_chai
n_chai

asked on

String preprocessing

Hi,

I'm trying to write a perl script to do the followings:

1. Calculate the number of words from a string.
2. Check the last word exist in a text file. If exist    move it to the beginning of the string.
3. Extract the first two word of the string.
4. Find the occurence of the word "d/o" and extract every words before that.

Eg.
   string = "Rajiv Mani d/o Arumugam"
   ...code to count the word length which is 4
   if (last_word "Arumugam" is in file c:\temp\Names.txt)
   {
     code to move last_word to first_word
     string = "Arumugam Rajiv Mani d/o"
     if (string has "d/o")
      code to extract "Arumugam Rajiv Mani"
     else
      code to retrieve "Arumugam Rajiv"

Thanks,
Nick

     




ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of n_chai
n_chai

ASKER

Hi User Ozo,

they seems to be some problem when my names has more than 4 words. eg "Abdul Aziz d/o Mohamad Yusoff"

the system will return me "Abdul Aziz  Mohamad" Any idea ?

Nick
Avatar of n_chai

ASKER

Hi User Ozo,

they seems to be some problem when my names has more than 4 words. eg "Abdul Aziz d/o Mohamad Yusoff"

the system will return me "Abdul Aziz  Mohamad" Any idea ?

Nick
Avatar of n_chai

ASKER

Hi User Ozo,

they seems to be some problem when my names has more than 4 words. eg "Abdul Aziz d/o Mohamad Yusoff"

the system will return me "Abdul Aziz  Mohamad" Any idea ?

Nick
When I run it with
$string = "Abdul Aziz d/o Mohamad Yusoff";m
"Yusoff Abdul Aziz "
When I run it with
$string = "Abdul Aziz d/o Mohamad Yusoff";
I get
"Yusoff Abdul Aziz " 
in $extract
Avatar of n_chai

ASKER

Hi Ozo,

I think I made a mistake in my requirements. Actually what I need to do is whenever the system detected "d/o" I just need the words before it. eg. "Abdul Aziz d/o Mohamad Yusoff" I need "Abdul Aziz" only.

Sorry.
my $string = "Abdul Aziz d/o Mohamad Yusoff";
$string =~ m/^(.*)d\/o/;
print "$1\n";