Link to home
Start Free TrialLog in
Avatar of baz_can_fix_it
baz_can_fix_it

asked on

Sorting content of table within a html page Perl CGI or Perl script

Hi Experts

I have a content of html page looks like this

...some html stuff here
<table width="600"><p>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041211.131223/index.html">Smith, Martin. Masters Thesis, 1991</a><p></td></tr>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041212.133427/index.html">Bush, J. W. (Joe Nogood). Masters Thesis, 1990</a><p></td></tr>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041215.124610/index.html">Focker, Mo. Masters Thesis, 1992</a><p></td></tr>
heaps more
</TABLE></CENTER></BODY></HTML>

Could some one please help me on how i go about sorting the table by the surname so it looks like this, in a seprate Perl CGI or perl script...

...some html stuff here
<table width="600"><p>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041212.133427/index.html">Bush, J. W. (Joe Nogood). Masters Thesis, 1990</a><p></td></tr>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041215.124610/index.html">Focker, Mo. Masters Thesis, 1992</a><p></td></tr>
<tr><td><font face=helvetica,arial><a href="/public/dep-20041211.131223/index.html">Smith, Martin. Masters Thesis, 1991</a><p></td></tr>
heaps more
</TABLE></CENTER></BODY></HTML>


This data is not comming from a databse so i can't achive this from that end...

Thanx in Advance
SOLUTION
Avatar of kandura
kandura

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kandura
kandura

This is the output:

<html>
    <head>
    </head>
    <body>
        <center>
            <table width=600>
                <tr>
                    <td>
                        <p>
                    </td>
                </tr>
                <tr>
                    <td><font face="helvetica,arial"><a href="/public/dep-20041212.133427/index.html">Bush, J. W. (Joe Nogood). Masters Thesis, 1990</a><p></font></td>
                </tr>
                <tr>
                    <td><font face="helvetica,arial"><a href="/public/dep-20041215.124610/index.html">Focker, Mo. Masters Thesis, 1992</a><p></font></td>
                </tr>
                <tr>
                    <td><font face="helvetica,arial"><a href="/public/dep-20041211.131223/index.html">Smith, Martin. Masters Thesis, 1991</a><p></font></td>
                </tr>
            </table>
        </center>
    </body>
</html>
Avatar of baz_can_fix_it

ASKER

Hi kandura
Thanx for the quick responce

Any other ways without the use of HTML::TreeBuilder; Doesnt look like they have that library on the server

Can't locate HTML/TreeBuilder.pm in @INC (@INC contains: /usr/perl5/5.00503/sun4
-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/s
ite_perl/5.005 .) at /../apache/cgi-bin/test.pl line 3.
BEGIN failed--compilation aborted at /../apache/cgi-bin/test.pl line 3.

Cheers
Why don't you install it then? I really think this is about the shortest _and_ safest method.
I don't have rights on that server, i'll place a call with them, will take few days... I'll get back to you once installed ...

Thanx Heaps
baz_can_fix_it,
> I don't have rights on that server,

You don't have shell access to that machine? that's a pity.

BTW, do you have to do the sorting on that server? Or could you do it on your own machine?

In any case, installing HTML::TreeBuilder will be a great addition to your toolbox. As you can see, it makes screen scraping and digging around in html a breeze :-)
Unfortunaly it has to be on that machine, the big problem we have is that machine is using perl for heaps of other imporatnt programs and we can't efford to mess around with the libraries...But they are going to see what they can do...Cheers
Avatar of Tintin
There's also the option of using Javascript to dynamically sort any of the columns in a table.  Depends on how much data you are displaying.
Hi Tintin

Java script would be great, that way i don't have to install anything on server side...but woyld need help with that as my javascripting is not that good...

Cheers
do you mean to use a CGI to sort the ready (existing) html file?
Are you aware that using JavaScript also requires access to the server?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would like to note that, although this javascript should work in most browsers, not everyone has javascript enabled. (I've tested in IE6 and Firefox).
(Much) older browsers might not work either.
All of those issues would be taken care of when you sort on the server prior to outputting the document.
> All you need to do is serve the html in question with an added <script> section ...
and how do you do that without access to the server?

anyway, nice script ;-)
kandura YOU ARE A LEGEND!!!!

Excellent answer, very happy with both your answers, but your JavaScript one works without any problems...Cheers

much appreciated

Thank you
Thanks for the huge compliment :-)

Good luck with your app!