in reply to Escaping an @ or a ^ in a format
#!/usr/bin/perl
%hash = qw(site.com 10 jamie@site.com:site1.com 4 user@hots:foo.bar 20);
eval print_url_info(\%hash,10,"STDOUT");
write;
exit 0;
sub print_url_info
{
my ($url_data,
$num_urls,
$fh)=@_;
my ($format)="",
($header)="$num_urls Most Popular URLs :",
($local_debug)=$debug,
($index)=0;
##############
# Geneate a string to be eval'd containing the most popular x urls for this user
$format = "format $fh =\n";
$format = $format . "<!--- Start User Top URLS Section -->\n";
$format = $format . "<font size=3><u>$header</u></font><br><br>\n";
$format = $format . "<table border=0>\n <tr>\n";
$format = $format . " <th align=left>URL</th>\n";
$format = $format . " <th width=10></th>\n";
$format = $format . " <th align=left>Num of Hits</th>\n </tr>\n";
##############
# Print the urls in descending order
$index=0;
foreach (reverse
sort { ${$url_data}{$a} <=> ${$url_data}{$b} }
keys %{$url_data} )
{
$format = $format . " <tr>\n";
$format = $format . " <td align=left>$_</td>\n";
$format = $format . " <td align=right> ${$url_data}{$_} </td>\n </tr>\n";
( ++$index == $num_urls ) && last;
}
$format = $format . "</table>\n<br>\n";
$format = $format . "<!--- End User Top URLS Section -->\n";
$format = $format . "\n.\n";
return $format;
}
|
|---|