Home > Archive > PERL Beginners > February 2006 > Help with creating http links
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help with creating http links
|
|
|
| Hi,
I have a script which runs a regression and
generates a log of failed tests.
Eg: Test: dir1/test1.v failed
My manager wants me to create a link to the file, so
that if we click on the link the actual log pops up in
a browser. I know the path to open the test in a
browser, it's like
file:////a/b/c/dir1/test1.v
Till now I have only used Perl for mainly text
processing and I have no idea how to start on this.
It would be great if some one can suggest me where to
start from.
Thanks a lot,
Anu.
________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
| |
| Chas Owens 2006-02-27, 6:58 pm |
| On 2/27/06, anu p <anu_subj_info@yahoo.com> wrote:
> Hi,
>
> I have a script which runs a regression and
> generates a log of failed tests.
>
> Eg: Test: dir1/test1.v failed
>
> My manager wants me to create a link to the file, so
> that if we click on the link the actual log pops up in
> a browser. I know the path to open the test in a
> browser, it's like
> file:////a/b/c/dir1/test1.v
>
> Till now I have only used Perl for mainly text
> processing and I have no idea how to start on this.
>
> It would be great if some one can suggest me where to
> start from.
>
> Thanks a lot,
> Anu.
This is still text processing. It is just a different target: html.=20
What you want is a file named log.html that contains the text:
<html>
<head>
<title>Log for X run on 2006-02-27 12:01:23</title>
</head>
<body>
Test: <a href=3D"file:////a/b/c/dir1/test1.v">dir1/test1.v failed</a><br />
Test: <a href=3D"file:////a/b/c/dir1/test2.v">dir1/test2.v failed</a><br />
Test: <a href=3D"file:////a/b/c/dir1/test5.v">dir1/test5.v failed</a><br />
</body>
</html>
You can get this by either parsing your original log or by writting
the original log with this information. Since I don't know what sort
of test harness you are using I will assume that I have a file with
the format:
Test: {testfile} failed
with one line per test failure. The (untested) code to generate the
html file would be
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my $filename =3D shift;
my $in =3D IO::File->new;
my $out =3D IO::File->new;
$in->open("<", $filename) or die "Could not open $filename for reading:$!";
$out->open(">", "$filename.html") or die "Could not open $filename for
writing:$!";
my $runtime =3D localtime(($in->stat)[9]);
$out->print("<html>\n<head>\n<title>Log for X run on
$runtime</title>\n</head>\n<body>");
while (my $line =3D <$in> ) {
next unless $line =3D~ /Test:\s+(.*)\s+failed/;
my $test =3D $1;
$out->print(qq(Test <a href=3D"file:////a/b/c/$test">$test</a><br />\n)=
);
}
$out->print("</body>\n</html>\n");
|
|
|
|
|