I have an XML file,
<doc>
<date name="processingtime">2011-04-09T11:12:22.049Z</date>
<str name="docuid">121422</str>
<str name="title">ABC</str>
<\doc>
<doc>
<date name="processingtime">2012-04-09T11:12:22.049Z</date>
<str name="docuid">13427</str>
<str name="title">CDE</str>
<\doc>
<date name="processingtime">2010-04-09T11:12:22.049Z</date>
<str name="docuid">89822</str>
<str name="title">LKK</str>
<\doc>
where a tag (<str name="docuid">) appears multiple times. i need to fetch data from all the docid tags and find max value from that. I used following code::
$html =~ s/<doc>/<doc>\n\n\n\n\n\n/g;
my (@lines) = split("\n\n\n\n\n", $html);
$cn = scalar(@lines);
for($i = 0; $i<$cn; $i++)
{
if ($lines[$i] =~ m/<str name="docuid">(.*?)<\/str>/)
{
$docuid[$i] = $1;
}
}
my $max = max @docuid;
This code is solving my purpose, but is there any better way to achieve this.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|