Re: Using regular expressions to insert tags
[email protected] ("Terrence Brannon") Wed, 21 Jun 2006 09:16:32 -0400
| Newsgroups | perl.scripts |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_54986_1170945.1150895792276 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Why not stick it in a hash and then use XML::Generator? On 6/20/06, Sriram Rajagopalan <[email protected]> wrote: > > Hello, > > I have a text file in a columnar format. There are seven entries in a row, > separated by tabs. > > eg. > > 1 23 555 34 Corporation Index Sediment > > This has to be tagged as: > > > <no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</status><value>Index</value><type>Sediment</type> > > I have stored the file contents to $_ and I am using the regex > > > $_=~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t/<no>$1<\/no><code>$2<\/code><set>$3<\/set><id>$4<\/id><status>$5<\/status><value>$6<\/value><type>$7<\/type>/g; > > I am not able to get the text tagged. Can anyone help me out to get my > desired codes? > > Thanks, > > Sriram > ------=_Part_54986_1170945.1150895792276 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Why not stick it in a hash and then use XML::Generator?<br><br><div><span class="gmail_quote">On 6/20/06, <b class="gmail_sendername">Sriram Rajagopalan</b> <<a href="mailto:[email protected]">[email protected] </a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div> <div> <p align="left"><font face="Verdana" size="2">Hello,</font></p> <p align="left"><font face="Verdana" size="2">I have a text file in a columnar format. There are seven entries in a row, separated by tabs.</font></p> <p align="left"><font face="Verdana" size="2">eg.</font></p> <p align="left"><font face="Verdana" size="2">1 23 555 34 Corporation Index Sediment</font></p> <p align="left"><font face="Verdana" size="2">This has to be tagged as:</font></p> <p align="left"><font face="Verdana" size="2"><no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</status><value>Index</value><type>Sediment</type> </font></p> <p align="left"><font face="Verdana" size="2">I have stored the file contents to $_ and I am using the regex</font></p> <p align="left"><font face="Verdana" size="2">$_=~s/([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t/<no>$1<\/no><code>$2<\/code><set>$3<\/set><id>$4<\/id><status>$5<\/status><value>$6<\/value><type>$7<\/type>/g; </font></p> <p align="left"><font face="Verdana" size="2">I am not able to get the text tagged. Can anyone help me out to get my desired codes?</font></p> <p align="left"><font face="Verdana" size="2">Thanks,</font></p> <p align="left"><font face="Verdana" size="2">Sriram</font></p> </div> </div></blockquote></div><br> ------=_Part_54986_1170945.1150895792276--