Re: Finally a better script!
- From: Nikos <hackeras@xxxxxxxxx>
- Date: Sat, 30 Apr 2005 01:19:31 +0300
Nikos wrote: old_script [snip]
Here is the script modified again implementing new ideas:
<code>
my %sql = (
get_counter => "SELECT counter FROM visitorlog",
get_host => "SELECT host FROM visitorlog WHERE host=?",
update_counter => "UPDATE visitorlog SET counter+=1",
update_visitorcounter => "UPDATE visitorlog SET visitorcounter+=1 WHERE host=?",
update_passage => "UPDATE visitorlog SET passage=? WHERE host=?",
insert_host => "INSERT INTO visitorlog (host, date, passage, visitorcounter, counter) VALUES (?, ?, ?, ?, ?)",
);
my $passage = param('select') || "Áñ÷éêÞ Óåëßäá!";
my ($data, @data);
if (param('select') and param('select') ne '..') { open(FILE, "<../data/text/$passage.txt") or die $!; @data = <FILE>; close(FILE);
$data = join('', @data); $sth = $dbh->prepare( $sql{update_passage} );
$sth->execute($passage, $host);
}
else
{
my $sth = $dbh->prepare( $sql{get_host} );
$sth->execute($host); if ($sth->rows)
{
$sth = $dbh->prepare( $sql{update_host} );
$sth->execute($host); $sth = $dbh->prepare( $sql{get_host} );
$sth->execute($host);$row = $sth->fetchrow_hashref;
$data = "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåò ôçí óåëßäá åíäéáöÝñïõóá!\n" .
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò " ..$row->{date}. " !!\n" .
"ÓýíïëéêÝò Þñèåò åäþ " .$row->{guestcounter}. " öïñÝò!!!\n" .
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{passage}. " }\n" .
"Ðïéü êåßìåíï èá ìåëåôÞóåòé áõôÞí ôçí öïñÜ !?";
}
else
{
if ($host ne "Íßêïò")
{
$data = "ÃåéÜ óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù íá âñåßò ôá êåßìåíá åíäéáöÝñïíôá :-)";
$sth = $dbh->prepare( $sql{insert_host} );
$sth->execute($host, $date, $passage, $guestcounter, $counter);
}
else
{
$data = "ÃåéÜ óïõ Íéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ íá óïõ ðÜíå ðÜíôá! ;-)";
}
}
}
</code>
I had trouble selecting good variable names but i think i have made good selections. Of course i changes the mysql columns names as well.
I like your %hash idea a lot in fact i put all the sql statements there.
I was also wondering if we can shorter it and perfect it even more maybe with subdivisions. :-)
.
- References:
- Finally a better script!
- From: Nikos
- Finally a better script!
- Prev by Date: [Golf-ish] Ordered hash keys
- Next by Date: Re: Finally a better script!
- Previous by thread: Re: Finally a better script!
- Next by thread: Windows Clipboard
- Index(es):