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> &lt;<a href="mailto:[email protected]">[email protected]
</a>&gt; 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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 23&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 555&nbsp;&nbsp;&nbsp;&nbsp; 34&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Corporation&nbsp;&nbsp;&nbsp;&nbsp; Index&nbsp;&nbsp; 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">&lt;no&gt;1&lt;/no&gt;&lt;code&gt;23&lt;/code&gt;&lt;set&gt;555&lt;/set&gt;&lt;id&gt;34&lt;/id&gt;&lt;status&gt;Corporation&lt;/status&gt;&lt;value&gt;Index&lt;/value&gt;&lt;type&gt;Sediment&lt;/type&gt;
</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/&lt;no&gt;$1&lt;\/no&gt;&lt;code&gt;$2&lt;\/code&gt;&lt;set&gt;$3&lt;\/set&gt;&lt;id&gt;$4&lt;\/id&gt;&lt;status&gt;$5&lt;\/status&gt;&lt;value&gt;$6&lt;\/value&gt;&lt;type&gt;$7&lt;\/type&gt;/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--