[url=http://perldoc.perl.org/functions/use.html][black][b]use[/b][/black][/url] [green]HTML::Parser[/green] [red]([/red][red])[/red][red];[/red]
[black][b]use[/b][/black] [green]strict[/green][red];[/red]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$url[/blue] = [red]"[/red][purple][URL unfurl="true"]http://foo.bar[/URL][/purple][red]"[/red][red];[/red]
[black][b]my[/b][/black] [blue]$content[/blue] = [url=http://perldoc.perl.org/functions/do.html][black][b]do[/b][/black][/url] [red]{[/red][url=http://perldoc.perl.org/functions/local.html][black][b]local[/b][/black][/url] [blue]$/[/blue][red];[/red] <DATA>[red]}[/red][red];[/red]
[black][b]my[/b][/black] [red]([/red][blue]$title[/blue], [blue]$sp_desc[/blue], [blue]$sp_keys[/blue], [blue]$sp_body[/blue][red])[/red][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][blue]$content[/blue][red])[/red] [red]{[/red]
[blue]$title[/blue] = [maroon]get_html_title[/maroon][red]([/red][blue]$content[/blue][red])[/red][red];[/red]
[blue]$sp_desc[/blue] = [maroon]unquote[/maroon][red]([/red][maroon]get_html_description[/maroon][red]([/red][blue]$content[/blue][red])[/red][red])[/red][red];[/red]
[blue]$sp_keys[/blue] = [maroon]unquote[/maroon][red]([/red][maroon]get_html_keywords[/maroon][red]([/red][blue]$content[/blue][red])[/red][red])[/red][red];[/red]
[blue]$sp_body[/blue] = [maroon]get_html_body[/maroon][red]([/red][blue]$content[/blue][red])[/red][red];[/red]
[gray]=comment[/gray]
[gray] my $sth = $dbh->prepare(qq{INSERT INTO metalink VALUES SET url=?, body=?, title=?});[/gray]
[gray] $sth->execute($url, $sp_body, $sp_title) or error("Can't execute: " . $dbh->errstr);[/gray]
[gray] $sth->finish; undef $sth;[/gray]
[gray] &start;[/gray]
[gray]=cut[/gray]
[red]}[/red]
[url=http://perldoc.perl.org/functions/print.html][black][b]print[/b][/black][/url] [red]<<"END_DEBUG"[/red][red];[/red]
[purple]Url = '[blue]$url[/blue]'[/purple]
[purple]Title = '[blue]$title[/blue]'[/purple]
[purple]Desc = '[blue]$sp_desc[/blue]'[/purple]
[purple]Keys = '[blue]$sp_keys[/blue]'[/purple]
[purple]Body = '[blue]$sp_body[/blue]'[/purple]
[red]END_DEBUG[/red]
[gray][i]#############################[/i][/gray]
[gray][i]### Supporting Fuctions[/i][/gray]
[url=http://perldoc.perl.org/functions/sub.html][black][b]sub[/b][/black][/url] [maroon]get_html_title[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$html[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$title[/blue] = [url=http://perldoc.perl.org/functions/undef.html][black][b]undef[/b][/black][/url][red];[/red]
[black][b]my[/b][/black] [blue]$p[/blue] = HTML::Parser->[maroon]new[/maroon][red]([/red]
[purple]start_h[/purple] => [red][[/red][black][b]sub[/b][/black] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$self[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[blue]$title[/blue] = [red]'[/red][purple][/purple][red]'[/red][red];[/red]
[blue]$self[/blue]->[maroon]handler[/maroon][red]([/red][purple]text[/purple] => [black][b]sub[/b][/black] [red]{[/red] [blue]$title[/blue] .= [blue]$_[/blue][red][[/red][fuchsia]0[/fuchsia][red]][/red][red];[/red] [red]}[/red], [red]'[/red][purple]dtext[/purple][red]'[/red][red])[/red][red];[/red]
[red]}[/red], [red]'[/red][purple]self[/purple][red]'[/red][red]][/red],
[purple]end_h[/purple] => [red][[/red][red]'[/red][purple]eof[/purple][red]'[/red], [red]'[/red][purple]self[/purple][red]'[/red][red]][/red],
[purple]report_tags[/purple] => [red][[/red][red]'[/red][purple]title[/purple][red]'[/red][red]][/red],
[red])[/red][red];[/red]
[blue]$p[/blue]->[maroon]parse[/maroon][red]([/red][blue]$html[/blue][red])[/red][red];[/red]
[url=http://perldoc.perl.org/functions/return.html][black][b]return[/b][/black][/url] [blue]$title[/blue][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]get_html_meta[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$html[/blue], [blue]$meta_name[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$content[/blue] = [black][b]undef[/b][/black][red];[/red]
[black][b]my[/b][/black] [blue]$p[/blue] = HTML::Parser->[maroon]new[/maroon][red]([/red]
[purple]start_h[/purple] => [red][[/red][black][b]sub[/b][/black] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$attr[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][url=http://perldoc.perl.org/functions/exists.html][black][b]exists[/b][/black][/url] [blue]$attr[/blue]->[red]{[/red]name[red]}[/red] && [blue]$attr[/blue]->[red]{[/red]name[red]}[/red] eq [blue]$meta_name[/blue][red])[/red] [red]{[/red]
[blue]$content[/blue] = [blue]$attr[/blue]->[red]{[/red]content[red]}[/red][red];[/red]
[red]}[/red]
[red]}[/red], [red]'[/red][purple]attr[/purple][red]'[/red][red]][/red],
[purple]report_tags[/purple] => [red][[/red][red]'[/red][purple]meta[/purple][red]'[/red][red]][/red],
[red])[/red][red];[/red]
[blue]$p[/blue]->[maroon]parse[/maroon][red]([/red][blue]$html[/blue][red])[/red][red];[/red]
[black][b]return[/b][/black] [blue]$content[/blue][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]get_html_description[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$html[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]return[/b][/black] [maroon]get_html_meta[/maroon][red]([/red][blue]$html[/blue], [red]'[/red][purple]description[/purple][red]'[/red][red])[/red][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]get_html_keywords[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$html[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]return[/b][/black] [maroon]get_html_meta[/maroon][red]([/red][blue]$html[/blue], [red]'[/red][purple]keywords[/purple][red]'[/red][red])[/red][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]get_html_body[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$html[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]my[/b][/black] [blue]$body[/blue] = [black][b]undef[/b][/black][red];[/red]
[black][b]my[/b][/black] [blue]$p[/blue] = HTML::Parser->[maroon]new[/maroon][red]([/red]
[purple]start_h[/purple] => [red][[/red][black][b]sub[/b][/black] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$self[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[blue]$body[/blue] = [red]'[/red][purple][/purple][red]'[/red][red];[/red]
[blue]$self[/blue]->[maroon]report_tags[/maroon][red]([/red][red])[/red][red];[/red]
[blue]$self[/blue]->[maroon]handler[/maroon][red]([/red][purple]start[/purple] => [black][b]undef[/b][/black][red])[/red][red];[/red]
[blue]$self[/blue]->[maroon]handler[/maroon][red]([/red][purple]default[/purple] => [black][b]sub[/b][/black] [red]{[/red] [blue]$body[/blue] .= [url=http://perldoc.perl.org/functions/shift.html][black][b]shift[/b][/black][/url][red];[/red] [red]}[/red], [red]'[/red][purple]text[/purple][red]'[/red][red])[/red][red];[/red]
[blue]$self[/blue]->[maroon]handler[/maroon][red]([/red][purple]end[/purple] => [black][b]sub[/b][/black] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$self[/blue], [blue]$tagname[/blue], [blue]$text[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[olive][b]if[/b][/olive] [red]([/red][blue]$tagname[/blue] eq [red]'[/red][purple]body[/purple][red]'[/red][red])[/red] [red]{[/red]
[blue]$self[/blue]->[maroon]eof[/maroon][red]([/red][red])[/red][red];[/red]
[red]}[/red] [olive][b]else[/b][/olive] [red]{[/red]
[blue]$body[/blue] .= [blue]$text[/blue][red];[/red]
[red]}[/red]
[red]}[/red], [red]'[/red][purple]self,tagname,text[/purple][red]'[/red][red])[/red][red];[/red]
[red]}[/red], [red]'[/red][purple]self[/purple][red]'[/red][red]][/red],
[purple]report_tags[/purple] => [red][[/red][red]'[/red][purple]body[/purple][red]'[/red][red]][/red],
[red])[/red][red];[/red]
[blue]$p[/blue]->[maroon]parse[/maroon][red]([/red][blue]$html[/blue][red])[/red][red];[/red]
[black][b]return[/b][/black] [blue]$body[/blue][red];[/red]
[red]}[/red]
[black][b]sub[/b][/black] [maroon]unquote[/maroon] [red]{[/red]
[black][b]my[/b][/black] [red]([/red][blue]$string[/blue][red])[/red] = [blue]@_[/blue][red];[/red]
[black][b]return[/b][/black] [olive][b]if[/b][/olive] ! [url=http://perldoc.perl.org/functions/defined.html][black][b]defined[/b][/black][/url] [blue]$string[/blue][red];[/red]
[blue]$string[/blue] =~ [red]s/[/red][purple][[purple][b]\"[/b][/purple][purple][b]\'[/b][/purple]][/purple][red]/[/red][purple][/purple][red]/[/red][red]g[/red][red];[/red] [gray][i]#remove quotes[/i][/gray]
[black][b]return[/b][/black] [blue]$string[/blue][red];[/red]
[red]}[/red]
[fuchsia]1[/fuchsia][red];[/red]
[gray][i]#############################[/i][/gray]
[gray][i]### Data Block[/i][/gray]
[teal]__DATA__[/teal]
[teal]<html>[/teal]
[teal]<head>[/teal]
[teal]<title>My Title</title>[/teal]
[teal]<meta name="description" content="My Description">[/teal]
[teal]<META CONTENT="My Keywords" NAME="keywords">[/teal]
[teal]</head>[/teal]
[teal]<body bgcolor="white">[/teal]
[teal]<b>Mary</b> had a little lamb<br />[/teal]
[teal]Then the lamb ate <b>Mary</b><br />[/teal]
[teal]And it was little no more<br />[/teal]
[teal]</body>[/teal]
[teal]</html>[/teal]