Nik has asked for the wisdom of the Perl Monks concerning the following question:
ok with the above script iam trying to see if the current hostname of a visitor exists in guestlog mysql database. If it does then i just update the existing record, if it does not i just welcome the user. Please you asked me to ask specific questions and here i ask one: Is the above logic correct? Is there any betetr that i can write it? ps. Sorry about the Greek folks but although i use UTF-8 it still being displayed like shit. I hate seeing it myself too but i donw know how can they be displayed correctly.my $script = param('select') or "Αρχική Σελίδα!"; $sth = $dbh->prepare( "SELECT host FROM guestlog" ); $sth->execute(); while( $row = $sth->fetchrow_hashref ) { if( $host eq $row->{host} ) { my $hostmatch = 1; } } if( param('select') and param('select') !~ /\.\./ ) { open(FILE, "<../data/text/$script.txt") or die $!; my @data = <FILE>; close(FILE); my $data = join('', @data); $dbh->do( "UPDATE guestlog SET script='$script' WHERE host='$host' +" ) or die $dbh->errstr; } elsif( $hostmatch == 1 ) { $dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE hos +t='$host'" ) or die $dbh->errstr; $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE host='$host'" +); $sth->execute(); $row = $sth->fetchrow_hashref; $data = "Καλώς ήλθες " .$host. "! Χαίρομαι που βρίσκες την σελίδα +ενδιαφέρουσα!\n" . "Τελευταία φορά ήρθες εδώ ως " .$row->{host}. " στις " .$r +ow->{date}. " !!\n" . "Σύνολικές ήρθες εδώ " .$row->{hostcount}. " φορές!!!\n" . "Τελευταία είδες το κείμενο { " .$row->{script}. " }\n" . "Ποιό κείμενο θα μελετήσεςι αυτήν την φορά !?"; } elsif( $hostmatch != 1 ) { if ( $host ne "Νίκος" ) { $data = "Γειά σου " .$host. "!\n" . "Έρχεσαι για 1η φορά εδώ !!\n" . "Ελπίζω να βρείς τα κείμενα ενδιαφέροντα :-)"; $dbh->do( "INSERT INTO guestlog VALUES (null, '$host', '$date', + '$script', 1, 1)" ) or die $dbh->errstr; } else { $data = "Γειά σου Νικόλα, τι χαμπάρια?! Όλα δεξιά να σου πάνε π +άντα! ;-)"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is this logic correct? Maybe can be rewritten better?
by dragonchild (Archbishop) on Apr 29, 2005 at 15:09 UTC | |
by Nik (Initiate) on Apr 29, 2005 at 15:24 UTC | |
by ikegami (Patriarch) on Apr 29, 2005 at 15:32 UTC | |
| |
by Fletch (Bishop) on Apr 29, 2005 at 16:23 UTC | |
by Nik (Initiate) on Apr 29, 2005 at 16:43 UTC | |
by Fletch (Bishop) on Apr 29, 2005 at 17:13 UTC | |
|
Re: Is this logic correct? Maybe can be rewritten better?
by ikegami (Patriarch) on Apr 29, 2005 at 15:14 UTC | |
| |
|
Re: Is this logic correct? Maybe can be rewritten better?
by trammell (Priest) on Apr 29, 2005 at 15:00 UTC | |
by ikegami (Patriarch) on Apr 29, 2005 at 15:06 UTC | |
|