
KevinR
Veteran

Feb 15, 2008, 3:26 PM
Post #11 of 18
(6952 views)
|
Re: [msing005] how to read fieldname from a differnt HTML file
[In reply to]
|
Can't Post
|
|
The code you posted earlier is a little confusing, but see how well this works, I can't test it so I would be surprised if it did not need some tweaking to get working with your files:
#!c:/perl/bin/perl use strict; use CGI::Carp qw/fatalsToBrowser/; use CGI; my $newsVariable = CGI->new; #creating new object from CGI.pm class #opening Directory opendir(DIR,"./") or die "Can't opendir: $!"; my @files = grep {/^item/} readdir(DIR); close(DIR); #Starting html print $newsVariable->header(), $newsVariable->start_html(-title=>"News"), $newsVariable->h1("HEADLINES"), $newsVariable->start_table({-width=>400,-border=>'1'}),"\n\n", $newsVariable->start_Tr,$newsVariable->start_th,"Date",$newsVariable->end_th, $newsVariable->start_th,"Abstract",$newsVariable->end_th,$newsVariable->end_Tr; foreach my $file ( @files ){ print $newsVariable->start_Tr; open(ITEM,"./$file");# opening the item file my ($date, $abstract); while (<ITEM>) { if (/<meta\s+name=["']?rel_date["']?\s+content=["']?([^>]+)>/i) { $date = $1; $date =~ s/["']$//; } elsif (/<meta\s+name=["']?abstract["']?\s+content=["']?([^>]+)>/i) { $abstract = $1; $abstract =~ s/["']$//; } if ($date && $abstract) { print $newsVariable->start_th, $date, $newsVariable->end_th, $newsVariable->start_th, $abstract, $newsVariable->a({-href=>"./$file"},"More>>>"), $newsVariable->end_th, $newsVariable->end_Tr; last; close ITEM; } else { next; } } } print $newsVariable->end_table, $newsVariable->end_html(); -------------------------------------------------
|