Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort HTML file

Status
Not open for further replies.

eatr

Technical User
Jan 20, 2006
48
I'm a Perl dabbler looking to write a program to facilitate my handicapping hobby.

below is a typical chart running line

<table width="100%" cellspacing=0 cellpadding=2><tr bgcolor="#F9D900" align=left><th>#</th><th>Horse</th><th>1/4</th><th>1/2</th><th>Str</th><th>Fin</th></tr>

<tr><td bgcolor="#DFDFCE"><b> 6</b></td><td><b>Towering Escape</b></td><td>1<sup>1/2</sup></td><td>1<sup>1/2</sup></td><td>1<sup>4</sup></td><td>1<sup>3 1/4</sup></td></tr>

<tr><td bgcolor="#DFDFCE"><b> 2</b></td><td><b>Love Strikes</b></td><td>3<sup>1/2</sup></td><td>3<sup>1/2</sup></td><td>2<sup>1</sup></td><td>2<sup>1 1/2</sup></td></tr>

<tr><td bgcolor="#DFDFCE"><b> 3</b></td><td><b>Mutakaway</b></td><td>4<sup>1</sup></td><td>4<sup>4</sup></td><td>4<sup>8</sup></td><td>3<sup>1 1/4</sup></td></tr>

<tr><td bgcolor="#DFDFCE"><b> 1</b></td><td><b>How 'bout No</b></td><td>2<sup>1 1/2</sup></td><td>2<sup>2</sup></td><td>3<sup>1/2</sup></td><td>4<sup>8 1/4</sup></td></tr>

<tr><td bgcolor="#DFDFCE"><b> 5</b></td><td><b>Heavenly Psalm</b></td><td>5<sup>&nbsp;</sup></td><td>5<sup>&nbsp;</sup></td><td>5<sup>&nbsp;</sup></td><td>5<sup>&nbsp;</sup></td></tr>
</table>

Focusing only on the numbers and the superscripts immediately following them: The number to the left indicates the running position at a
particular call, the superscript value is the number of lengths this particular horse is AHEAD of the horse directly behind it.

What I need to do is convert lengths ahead to lengths behind. This would mean that for the last place horse,
for example, we would sum the superscript value of all
the horses ahead of it at a given call. (So this value for
the leading horse, at each call, would be ZERO).

Here's the question? Can I do this without actually
pulling out the data and inserting into a 2D array,
then sorting. In other words, can I sort this in the
HTML file?

Not looking for someone to write the code, just to give
me some suggestions.

Thanks
 
Can I do this without actually
pulling out the data and inserting into a 2D array,
then sorting. In other words, can I sort this in the
HTML file?

No. You will need to create a data set you can sort.


- Kevin, perl coder unexceptional!
 
Thanks

Thought as much but wanted to make sure there wasn't an easier way.

In a file of this sort, would you just write a regex to pull out the data or use HTML::parse?

 
I would try using regexps first. If that proves unreliable then you can try the parser.

- Kevin, perl coder unexceptional!
 
Assuming you are going to run this regularly, decide what data you want to collect, and design a structure for it (hash, hash of hashes, array, array of hashes, flat file, etc.). This will be your 'canonical form'. Then write your parsing code to read the HTML and get it into your standard form. Then do whatever you need to process that data.

This isolates your parsing from your processing, so if the owner of the website decides to re-skin the site or redesign their pages, you only have to fix your parser, not your whole code base...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top