
June 24th, 2004, 10:53 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 22
Time spent in forums: 20 m 13 sec
Reputation Power: 0
|
|
|
Putting Perl into WML file?
I was wondering how to run a perl script in a WML file. Would I just use the <perl> </perl> tags? That seems too easy, maybe it's an evil trick...
Seriously, I've got a perl script to dynamically list XML files in a directory, with the names in the list extracted from the relevent tags in those XML files (convoluted sentence or what?). So I'm looking to have that same structure for my WML file! But I'm not sure how to do this.
A quick view:
Code:
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
sub parse_line{
my $tag = shift;
my $buffer = shift;
my $temp = index($buffer, "<$tag>");
if ($temp != -1) {
my $search = substr($buffer, $temp+length("<$tag>"));
my $contents = substr($search, 0, index($search, "</$tag>"));
return $contents;
} else {
return '';
}
}
foreach(<*.xml>){
print "<br><br>\n";
my $foundtag = 0;
open(fh, $_);
while (!eof (fh)) {
$buffer = <fh>;
$contents = parse_line('TITLE', $buffer); # search for and extract <TITLE>
$last_modified = (stat($_))[9]; # get the file time
$age = time; # get current time
# handle <TITLE>
if (($contents ne '') && (((gmtime($age-$last_modified))[7]) < 15)) {
print "</a> <img src=\"new.gif\"> <a href=\"standardbrowser.php?x=$_\" target=\"content\"><font size=-1>$contents";
$foundtag = 1;
}
elsif ($contents ne '') {
print " <a href=\"standardbrowser.php?x=$_\" target=\"content\"><font size=-1>$contents";
$foundtag = 1;
}
# discard contents
$contents = '';
$contents = parse_line('SUBTITLE', $buffer); # search for and extract <SUBTITLE>
# handle <SUBTITLE>
if ($contents ne '') {
print " :<font size=-1>$contents</font></a>";
$foundtag = 1;
}
# discard contents
$contents = '';
if ($contents eq ''){ $contents = parse_line('AKA', $buffer);} # search for and extract <AKA>
# handle <AKA>
if ($contents ne '') {
print "</a><br><i><font size=-1 color=#FF0000>a.k.a. $contents</i></font>";
$foundtag = 1;
}
# discard contents
$contents = '';
if ($contents eq ''){ $contents = parse_line('AKA2', $buffer);} # search for and extract <AKA2>
# handle <AKA2>
if ($contents ne '') {
print "</a><br><i><font size=-1 color=#FF0000>a.k.a. $contents</i></font>";
$foundtag = 1;
}
# discard contents
$contents = '';
if ($contents eq ''){ $contents = parse_line('AKA3', $buffer);} # search for and extract <AKA3>
# handle <AKA3>
if ($contents ne '') {
print "</a><br><i><font size=-1 color=#FF0000>a.k.a. $contents</i></font>";
$foundtag = 1;
}
# discard contents
$contents = '';
if ($contents eq ''){ $contents = parse_line('AKA4', $buffer);} # search for and extract <AKA4>
# handle <AKA4>
if ($contents ne '') {
print "</a><br><i><font size=-1 color=#FF0000>a.k.a. $contents</i></font>";
$foundtag = 1;
}
# discard contents
$contents = '';
if ($contents eq ''){ $contents = parse_line('AKA5', $buffer);} # search for and extract <AKA5>
# handle <AKA5>
if ($contents ne '') {
print "</a><br><i><font size=-1 color=#FF0000>a.k.a. $contents</i></font>";
$foundtag = 1;
last;
}
}
close (fh);
if ($foundtag == 0)
{
print " - ";
}
}
Where in the WML file would it go? Could the WML or WAP browser handle this? Ack!! Any help is appreciated!!
Thanks!!
|