CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Clarification Required on Perl Tag Changes


New User

Sep 20, 2013, 6:55 AM

Post #1 of 2 (460 views)
Clarification Required on Perl Tag Changes Can't Post

Dear Guru's,

I'm a beginner of Perl Programming, I tried to create a perl script with small requirement. I derived around 90% small work but only one case I can't able to complete. Please help me on this to complete my first script.

Input File

<ref id="ref0001"><mixed-citation publication-type="journal"><label>1.</label> <string-name><surname>Meeran</surname> <given-names>SM</given-names></string-name>, <string-name><surname>Katiyar</surname> <given-names>S</given-names></string-name>, <string-name><surname>Elmets</surname> <given-names>CA</given-names></string-name>, <string-name><surname>Katiyar</surname> <given-names>SK</given-names></string-name>. <article-title>Interleukin-12 deficiency is permissive for angiogenesis in UV radiation-induced skin tumors</article-title>. <source>Cancer Res</source><year>2007</year>; <volume><bold>67</bold></volume>: <fpage>3785</fpage>–<lpage>3793</lpage>.</mixed-citation></ref>

Required Output File

<ref id="R1"><no>1.</no><cit type="journal"> <au><lname>Meeran</lname> <fname>SM</fname></au>, <au><lname>Katiyar</lname> <fname>S</fname></au>, <au><lname>Elmets</lname> <fname>CA</fname></au>, <au><lname>Katiyar</lname> <fname>SK</fname></au>. <atitle>Interleukin-12 deficiency is permissive for angiogenesis in UV radiation-induced skin tumors</atitle>. <source>Cancer Res</source><yr>2007</yr>; <vol><B>67</B></vol>: <fpage>3785</fpage>–<lpage>3793</lpage>.</cit></ref>

Here, tag
<mixed-citation publication-type="journal"><label>1.</label> ----</mixed-citation>

need to convert as

"<no>1.</no><cit type="journal">-----</cit>"

Script I used

$xmlcont =~ s#(<mixed-citation publication-type="journal">)(<label>\d</lable>)#<\2\1>#gi;


There is no changes in my output file.

(This post was edited by vkchan on Sep 20, 2013, 7:05 AM)

Veteran / Moderator

Sep 20, 2013, 7:20 AM

Post #2 of 2 (454 views)
Re: [vkchan] Clarification Required on Perl Tag Changes [In reply to] Can't Post

I've looked over this and your other related question and I see a big can of worms and I don't have the time or desire to attempt to figure out your real goal. But I will give you some advise.

First, DON'T use a series of regex's to parse XML data. Use one (or more) of the XML parsers on CPAN.

You should look over some of these choices.

Here are several primary candidates from that list.

XML::Twig - A perl module for processing huge XML documents in tree mode.

XML::LibXML::Parser - Parsing XML Data with XML::LibXML

XML::Rules - parse XML and specify what and how to keep/process for individual tags


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives