in reply to Re^4: merging a file with a value present in another file
in thread merging a file with a value present in another file

I'm not sure why the MCL clause doesn't show up in your output sample. But I'd say you have a two-step process, possibly involving two hashes:

  1. Go through file1, parsing out the beginning and end word in each clause, putting them in a %start hash and an %end hash respectively, with the tag (RP, MCL) as the keys' values.
  2. Go through file2, checking the first word of each line to see if it exists in one of these hashes, and if so, add the appropriate tag to the end of the line.

The rest is just implementation.

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^6: merging a file with a value present in another file
by lakssreedhar (Acolyte) on Jul 17, 2012 at 04:40 UTC

    I want the MCL tag also.I am new to perl,is it using regular expression that i can parse the start and end of each clause.Also i want the program to run for many such files.

      Yes, you can use a regex to get the words from file1 that you're going to search for and insert into file2. There are many different ways it could be written, but here's one example:

      my $str = q|{RP}makaravilYakkin Sabarimala ayyappanu cArZwwAnulYlYa wi +ruviwAMkUrZ rAjAvAyirunna SrI ciwwirawirunnAlYZ bAlarAmavarZmma natak +k vacca 420 kilogrAM wUkkamulYlYa wafkayafki{/RP}{MCL} sUkRikkunnaw +I kRewrawwilAN.{/MCL}|; while ($str =~ m[ {(\w+)} # a word within {}, capture it \W* # maybe non-word chars (\w+) # first word after tag, capture it [^{]+ # anything but a {, up to... \W # a non-word character (\w+) # last word before tag, capture it \W* # maybe non-word chars {/\1} # ending tag matching captured one above ]xg){ print "$1 $2 $3\n"; # print captured values }

      Aaron B.
      Available for small or large Perl jobs; see my home node.

        thanks i got the output
      Use XML::Parser to get the hashes as mentioned above for RP and MCL tags from f1 file. Then start with f2 file and update the lines by comparing them or checking them in hashes. I believe you need to add end_clause where you find the value of any hash once read again - for this thing keep adding the read keys in some separate data structure so that you can keep a record of read names and add end_clause