aakikce has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I want to tag separte authors from the following author list. Authos may come in any order in input(surname, givenname).
I have updated the input and output
Input:
<surname>Coff</surname>, <givenname>D.,</givenname>, <surname>Coff</surname>, <givenname>D.,</givenname>
<givenname>D.,</givenname>, <surname>Coff</surname>, <givenname>D.,</givenname>, <surname>Coff</surname>
Output:
<au><surname>Coff</surname>, <givenname>D.,</givenname></au>, <au><surname>Coff</surname>, <givenname>D.,</givenname></au>
<au><givenname>D.,</givenname>, <surname>Coff</surname></au>, <au><givenname>D.,</givenname>, <surname>Coff</surname></au>
I tried like below. But I got wrong once givenname comes first.
undef $/; $content = <DATA>; $content =~s#([^<]*)(<(?:sur|given)name>.*</(?:sur|given)name>)#$1."<a +uthorfield>".&indivauth($2)."</authorfield>"#egi; sub indivauth { $au{sur} = 'given'; $au{given} = 'sur'; ($inline) = @_; $inline =~s#(<surname>(?:(?!<sur|</au>).)*?</givenname>)#<au>$1</a +u>#gsi; return "$inline"; } open (FOUT, "> out.txt"); print FOUT $content;
Can you help me
Thanks
aakikce
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tag a matched text
by GrandFather (Saint) on Apr 16, 2007 at 13:20 UTC | |
| |
|
Re: tag a matched text
by wfsp (Abbot) on Apr 16, 2007 at 15:44 UTC | |
|
Re: tag a matched text
by Samy_rio (Vicar) on Apr 16, 2007 at 11:58 UTC | |
|