file test.txt where first entry is the name in db columns and second is name that is in html files used for parsing.
i make a search using the second elements on every line
name and stream location has a _ before and after becuause i dnt parse them from file . i simply assign them value /
name _Name_
age age
stream_loc _Stream Location_
i make a search using the second elements on every line
name and stream location has a _ before and after becuause i dnt parse them from file . i simply assign them value /
name _Name_
age age
stream_loc _Stream Location_
<html><body> age: 2<br></body></html>
this means the html file entries are not being parsed.or if parsed but not assinged to the hash variable ..
there is no problem with first and last element i can get their values correctly in db. but not for age.
Code:
#!/perl/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use File::Find; use DBI; use HTML::Scrubber; use Tie::IxHash; print header; my $count=0; my $lines; #=============================================================================== #first entry is the database column name and second is the file parameter name which is to be parsed from file open FILE,"test.txt"; while(<FILE>) { push @query_ref,[split]; } #print $query_ref[1][1]; close (FILE); #=============================================================================== #Defining directory of the location of streams my $dir="C:/type"; #Connection String my $dbh=DBI->connect('dbi:Oracle:test1','scott','tiger',{RaiseError => 1, AutoCommit => 1})or die "Can't connect to database $DBI::errstr\n"; my %params=(); find(\&edits,$dir); sub edits { if (/\.html$/) #looks for html files in folder { $count++; print "<BR>$count)..<BR>"; my $scrubber = HTML::Scrubber->new; #initialize html scrubber tie %params,"Tie::IxHash"; open(FILE,$File::Find::name) or die $!; while(defined(my $line = <FILE>)) { my $line= $scrubber->scrub($line); #scrub all html Tags $params{$query_ref[0][1]}{$_} = 1; $params{$query_ref[1][1]}={}; $params{$query_ref[2][1]}{$File::Find::name} = 1; foreach my $key (keys %params) { if($line=~/$key/) { print "<br>$line"; #[B]when age: 23 appears it prints #correctly[/B] if($line =~ m/: (.*)/) { $params{$key}{$1} = 1; #[B]<<<==i think here is #prob[/B] } } } #------------------SPECIAL CASES------------------------------------------------ } } # Transform hash data into 'xxx,yyy,zzz' forms as needed foreach my $key (keys %params) { $params{$key} = join(',', keys(%{$params{$key}})); if (!$params{$key}) { $params{$key} = 'Absent'; } } for my $key ( keys %params ) { my $value = $params{$key}; print "<Br>$key => $value<BR>"; } my $query = "insert into pooja values ('" .join("','", map { $params{$$_[1]} } @query_ref) . "')"; my $sql=qq{$query}; my $sth=$dbh->prepare($sql); $sth->execute(); close(FILE); } print "<br>$count files updated"; $dbh->disconnect if defined($dbh);
Comment