Re: Using regular expressions to insert tags
[email protected] (Geoffrey Leach) Wed, 21 Jun 2006 08:56:13 -0700
| Newsgroups | perl.scripts |
|---|---|
| Message-ID | <[email protected]> |
To assist you in finguring this out, you might try recoding using
s { }{ }/x - and lay out your regex over several lines so as to better =20
see what's going on. Also, if your data is consistent, (\d+)\s+ would =20
be lots faster.
On 06.20 07:19, Sriram Rajagopalan wrote:
> Hello,
>=20
> I have a text file in a columnar format. There are seven entries in a
> row,
> separated by tabs.
>=20
> eg.
>=20
> 1 23 555 34 Corporation Index Sediment
>=20
> This has to be tagged as:
> <no>1</no><code>23</code><set>555</set><id>34</id><status>Corporation</st=
atu
> s><value>Index</value><type>Sediment</type>
>=20
> I have stored the file contents to $_ and I am using the regex
>=20
> $_=3D~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<\/statu=
s><
> value>$6<\/value><type>$7<\/type>/g;
>=20
> I am not able to get the text tagged. Can anyone help me out to get my
> desired codes?
>=20
> Thanks,
> Sriram
>=20