Perfecting index.pl some more!

N

Nikos

Here is how my script has been transformed thanks to your precious
precious suggestions and mine's minor alternation:

#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard);
use CGI::Cookie;
use DBD::mysql;
use DBI;
use POSIX qw(strftime);

print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../data/css/style.css', -title=>'Øõ÷ùöåëÞ Ã
+íåõìáôéêÜ Êåßìåíá!', -background=>'../data/images/night.gif' );

my ($sth, $row);
my $date = strftime( "%d %b, %H:%M", localtime );
my $host = $ENV{'REMOTE_HOST'};
$host = "Ãßêïò" if ( ($host eq "dell") or ($host eq "localhost") or ($
+host ~= /vivodi.gr/) );

my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', 'c
+ensored')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', 'c
+ensored')
or {RaiseError=>1};

#*********************************************************************
+**********

my @files = <../data/text/*.txt>;
my @display_files = map( /([^\/]+)\.txt/, @files );

print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'}, '
+ÄéÜëåîå Ãíá áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => ' ),
popup_menu( -name=>'select', -value
+s=>\@display_files ),
submit('ÅðéëïãÞ'));
print end_form(), br();

my %sql = (
get_counter => "SELECT counter FROM visitorlog",
get_host => "SELECT host FROM visitorlog WHERE host=?",
update_visitor => "UPDATE visitorlog SET counter+=1 WHERE host=?",
update_passage => "UPDATE visitorlog SET passage=? WHERE host=?",
insert_host => "INSERT INTO visitorlog (null, host, date, passa
+ge, counter) VALUES (?, ?, ?, ?, ?, ?)"
);

my $passage = param('select') || "Ãñ÷éêÞ Óåëßäá!";
my ($data, @data);


if (param('select') and param('select') != '..')
{
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_visitor} );
$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->{counter}. " öïñÃò!!!\n"
+ .
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{passage}. " }\
+n" .
"Ãïéü êåßìåíï èá ìåëåôÞóåòé áõôÞí ôçí öïñÜ !?";
}
else
{
if ($host ne "Ãßêïò")
{
$data = "ÃåéÜ óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù íá âñåßò ôá êåßìåíá åíäéáöÃñïíôá :)";

$sth = $dbh->prepare( $sql{insert_host} );
$sth->execute(null, $host, $date, $passage, $counter);
}
else
{
$data = "ÃåéÜ óïõ Ãéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ íá óïõ ð
+Üíå ðÜíôá! ;-)";
}
}
}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

#*********************************************************************
+**********
print <<ENDOFHTML;
<html><head><title></title>
<script type='text/javascript'>

var textToShow = "$data";
var tm;
var pos = 0;
var counter = 0;

function init()
{ tm = setInterval("type()", 45) }

function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("DivText");
c = textToShow.charAt(pos++);

if (c.charCodeAt(0) != 10)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));

counter++;

if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press any key..."));
counter = 0;
clearInterval(tm);
document.body.onkeypress = function () {
document.getElementById("DivText").innerHTML = '';

tm = setInterval("type()", 50);
document.body.onkeypress = null; };
}
}
else
clearInterval(tm);
}
</script>

<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
ENDOFHTML
#*********************************************************************
+**********

print br(), br(), br();
print start_form(-action=>'show.pl');
print table( {class=>'user'},
Tr( td( 'Ãþò óå ëÃíå áäåëöå?'
+ ), td( textfield( 'name' ))),
Tr( td( 'ÃïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
»Êýñéå Éçóïý ×ñéóôÃ, ÅëÃçóïí Ìå« ?'
+ ), td( textarea( -name=>'pray', -rows=>4, -columns=>25 ))),
Tr( td( 'ÃåñéÃãñáøå ìáò ìéá ðñïóùðéêÞ óïõ
ðíåõìáôéêÞ åìðåéñßá áðü êÜðïéïí ãÃñïíôá ðñïò
þöåëïò ôùí õðïëïßðùí áäåëöþí ( áí öõóéêÜ Ã÷åéò :)'
+ ), td( textarea( -name=>'remark', -rows=>6, -columns=>25 ))),
Tr( td( 'Ãïéü åßíáé ôï email óïõ?'
+ ), td( textfield( 'email' ))),
Tr( td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí'
+ )), td( submit( 'ÃðïóôïëÞ' ))),
);
print end_form(), br(), br();

open(FILE, "<../data/text/tips") or die $!;
my @tips = <FILE>;
close(FILE);

@tips = grep { !/^\s*\z/s } @tips;
my $tip = $tips[ int(rand(@tips)) ];

print table( {class=>'tip'}, Tr( td( {class=>'tip'}, $tip ))), br();

$sth = $dbh->prepare( $sql{update_counter} ) if ($host ne "Ãßêïò");
$sth->execute;

$sth = $dbh->prepare( $sql{get_counter} );
$sth->execute;

#here i decided to add together all the times visitors visit
#my webpage so to get a total counter in order to avoid
#create a new mysql table called counters and store that
#value there. Or even to a flat file!
while ($row = $sth->fetchrow_hashref)
{
$counter += $row->{counter};
}

print table( {class=>'info'},
Tr( td( {class=>'host'}, $host )),
Tr( td( {class=>'date'}, $date )),
Tr( td( {class=>'counter'}, $counter ))
);

print br(), a( {href=>'games.pl'}, img{src=>'../data/
+images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?name=showlog'}, font(
+ {-size=>2, -color=>'Lime'}, b( 'Last Update: 30/4/2005' ))));


How i can i shorter it, perfect it some more by dividing into subs?
What must be/not be in a sub?
 
T

Tassilo v. Parseval

Also sprach Nikos:
Here is how my script has been transformed thanks to your precious
precious suggestions and mine's minor alternation:

#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard);
use CGI::Cookie;
use DBD::mysql;

I think you can drop that line as DBI will pull in the appropriate
database driver for you.
use DBI;
use POSIX qw(strftime);

print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../data/css/style.css', -title=>'Øõ÷ùöåëÞ Ð
+íåõìáôéêÜ Êåßìåíá!', -background=>'../data/images/night.gif' );

my ($sth, $row);
my $date = strftime( "%d %b, %H:%M", localtime );
my $host = $ENV{'REMOTE_HOST'};
$host = "Íßêïò" if ( ($host eq "dell") or ($host eq "localhost") or ($
+host ~= /vivodi.gr/) );

my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', 'c
+ensored')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', 'c
+ensored')
or {RaiseError=>1};

[ You should do something against long lines in your postings;
These continuation pluses make the code hard to read in a newsreader. ]
#*********************************************************************
+**********

my @files = <../data/text/*.txt>;
my @display_files = map( /([^\/]+)\.txt/, @files );

print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {-size=>5, -color=>'Lime'}, '
+ÄéÜëåîå Ýíá áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => ' ),
popup_menu( -name=>'select', -value
+s=>\@display_files ),
submit('ÅðéëïãÞ'));
print end_form(), br();

my %sql = (
get_counter => "SELECT counter FROM visitorlog",
get_host => "SELECT host FROM visitorlog WHERE host=?",
update_visitor => "UPDATE visitorlog SET counter+=1 WHERE host=?",
update_passage => "UPDATE visitorlog SET passage=? WHERE host=?",
insert_host => "INSERT INTO visitorlog (null, host, date, passa
+ge, counter) VALUES (?, ?, ?, ?, ?, ?)"
);

my $passage = param('select') || "Áñ÷éêÞ Óåëßäá!";
my ($data, @data);

@data should be declared in the smallest possible scope. So remove its
declaration.
if (param('select') and param('select') != '..')

The second conditions is most likely always true because you use the
wrong comparison-operator. String comparison is done with 'eq' and
'ne'.
{
open(FILE, "<../data/text/$passage.txt") or die $!;
@data = <FILE>;

my @data = said:
close(FILE);

$data = join('', @data);

No need to read the file linewise and then join the lines to one string.
Instead:

local $/; # enable slurp-mode
$data = <FILE>;

See $INPUT_RECORD_SEPARATOR in 'perldoc perlvar'.
$sth = $dbh->prepare( $sql{update_passage} );
$sth->execute($passage, $host);
}
else
{
[...]

}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

As you want shorter code, here's one way:

s/\n/\\n/g,
s/"/\\"/g ,
tr/\cM//d ,
for $data;
#*********************************************************************
+**********
print <<ENDOFHTML;
[...]

ENDOFHTML
#*********************************************************************
+**********

print br(), br(), br();

More concise:

print br() x 3;
print start_form(-action=>'show.pl');
print table( {class=>'user'},
Tr( td( 'Ðþò óå ëÝíå áäåëöå?'
+ ), td( textfield( 'name' ))),
Tr( td( 'ÐïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
»Êýñéå Éçóïý ×ñéóôÝ, ÅëÝçóïí Ìå« ?'
+ ), td( textarea( -name=>'pray', -rows=>4, -columns=>25 ))),
Tr( td( 'ÐåñéÝãñáøå ìáò ìéá ðñïóùðéêÞ óïõ
ðíåõìáôéêÞ åìðåéñßá áðü êÜðïéïí ãÝñïíôá ðñïò
þöåëïò ôùí õðïëïßðùí áäåëöþí ( áí öõóéêÜ Ý÷åéò :)'
+ ), td( textarea( -name=>'remark', -rows=>6, -columns=>25 ))),
Tr( td( 'Ðïéü åßíáé ôï email óïõ?'
+ ), td( textfield( 'email' ))),
Tr( td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí'
+ )), td( submit( 'ÁðïóôïëÞ' ))),
);
print end_form(), br(), br();

open(FILE, "<../data/text/tips") or die $!;
my @tips = <FILE>;
close(FILE);

@tips = grep { !/^\s*\z/s } @tips;

No need for the /s modifier (it only affects what '.' matches). Also,
but this is probably a matter of style, either write '/^\s*$/' or
'/\A\s*\z' for consistency. Better yet, avoid \A and \z altogether. They
are fairly uncommon (incidentally, I had to look up their meaning
first).
my $tip = $tips[ int(rand(@tips)) ];

The int() is reduntant here. Array-subscripts can only be integers, so
perl will truncate the number for you:

my $tip = $tips[ rand @tips ];
print table( {class=>'tip'}, Tr( td( {class=>'tip'}, $tip ))), br();

$sth = $dbh->prepare( $sql{update_counter} ) if ($host ne "Íßêïò");
$sth->execute;

$sth = $dbh->prepare( $sql{get_counter} );
$sth->execute;

#here i decided to add together all the times visitors visit
#my webpage so to get a total counter in order to avoid
#create a new mysql table called counters and store that
#value there. Or even to a flat file!
while ($row = $sth->fetchrow_hashref)
{
$counter += $row->{counter};
}

A flat file for a counter might in fact be a better idea than iterating
over an SQL-table. It should be less wasteful. In case you should use a
file, be aware of locking issues that have to be taken into account.
print table( {class=>'info'},
Tr( td( {class=>'host'}, $host )),
Tr( td( {class=>'date'}, $date )),
Tr( td( {class=>'counter'}, $counter ))
);

print br(), a( {href=>'games.pl'}, img{src=>'../data/
+images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?name=showlog'}, font(
+ {-size=>2, -color=>'Lime'}, b( 'Last Update: 30/4/2005' ))));


How i can i shorter it, perfect it some more by dividing into subs?
What must be/not be in a sub?

For a script of that length, functions are probably not required. The
logic is fairly linear and you're not jumping around in it too much.

Tassilo
 
N

Nikos

Tassilo v. Parseval wrote:
[snip suggestions to make the code better]

Thanks a lot Tassilo! :)
The code is much better now with your suggestions:
I dont know what to do with the long lines you said...
You said i dont have to use subs sicne this is nto a big script
and actually iam not repeating any functions more than once.

Well, ok, i dont know if it can gets any shorten than this or
if i can put tha javascript out in a seperate file but still pass the
$data variable.

Also maybe thre is a better wau to create the $data variable instead of
constant concatenations as i have it.



#!/usr/bin/perl
use strict;
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw:)standard);
use DBD::mysql;
use POSIX qw(strftime);

print header( -charset=>'iso-8859-7' );
print start_html( -style=>'/data/css/style.css', -title=>'Øõ÷ùöåëÞ
ÃíåõìáôéêÜ Êåßìåíá!', -background=>'/data/images/night.gif' );

my ($sth, $row);
my $date = strftime( "%d %b, %H:%M", localtime );
my $host = $ENV{'REMOTE_HOST'} or $ENV{'REMOTE_ADDR'};
$host = "Ãßêïò" if ( ($host eq "dell") or ($host eq "localhost") or
($host =~ /vivodi.gr/) );

my $dbh = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '****')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db', '****')
or {RaiseError=>1};

#*******************************************************************************

my @files = <../data/text/*.txt>;
my @display_files = map( /([^\/]+)\.txt/, @files );

print start_form(-action=>'index.pl');
print p( {-align=>'center'}, font( {class=>'tip'}, 'ÄéÜëåîå Ãíá
áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => ' ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ÅðéëïãÞ'));
print end_form(), br();

my %sql = (
get_counter => "SELECT counter FROM visitorlog",
get_host => "SELECT host FROM visitorlog WHERE host=?",
update_visitor => "UPDATE visitorlog SET counter+=1 WHERE host=?",
update_passage => "UPDATE visitorlog SET passage=? WHERE host=?",
insert_host => "INSERT INTO visitorlog (host, date, passage,
counter) VALUES (?, ?, ?, ?)"
);

my ($data, $counter);
my $passage = param('select') || "Ãñ÷éêÞ Óåëßäá!";

if (param('select') and param('select') !~ '..')
{
open(FILE, "<../data/text/$passage.txt") or die $!;
local $/;
$data = <FILE>;
close(FILE);

$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_visitor} );
$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->{counter}. " öïñÃò !!\n" .
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{passage}. " }\n" .
"Ãïéü êåßìåíï èá ìåëåôÞóåòé áõôÞí ôçí öïñÜ !?";
}
else
{
if ($host ne "Ãßêïò")
{
$data = "ÃåéÜ óïõ " .$host. "!\n" .
"¸ñ÷åóáé ãéá 1ç öïñÜ åäþ !!\n" .
"Åëðßæù íá âñåßò ôá êåßìåíá åíäéáöÃñïíôá :)";

$sth = $dbh->prepare( $sql{insert_host} );
$sth->execute($host, $date, $passage, $counter);
}
else
{
$data = "ÃåéÜ óïõ Ãéêüëá, ôé ÷áìðÜñéá?! ¼ëá äåîéÜ íá óïõ
ðÜíå ðÜíôá! ;-)";
}
}
}

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title>
<script type='text/javascript'>

var textToShow = "$data";
var tm;
var pos = 0;
var counter = 0;

function init()
{ tm = setInterval("type()", 45) }

function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("DivText");
c = textToShow.charAt(pos++);

if (c.charCodeAt(0) != 10)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));

counter++;

if (counter >= 1800 && (c.charCodeAt(0) == 10 || c == "."))
{
d.appendChild(document.createElement("br"));
d.appendChild(document.createTextNode("Press any key..."));
counter = 0;
clearInterval(tm);
document.body.onkeypress = function () {
document.getElementById("DivText").innerHTML = '';

tm = setInterval("type()", 50);
document.body.onkeypress = null; };
}
}
else
clearInterval(tm);
}
</script>

<body onload=init()>
<center>
<div id="DivText" align="Left" style="
background-image: url(../data/images/kenzo.jpg);
border: Ridge Orange 5px;
width: 850px;
height: 500px;
color: LightSkyBlue;
font-family: Times;
font-size: 18px;">
</div
ENDOFHTML
#*******************************************************************************

print br() x 3;
print start_form(-action=>'show.pl');
print table( {class=>'user_form'},
Tr( td( 'Ãþò óå ëÃíå áäåëöå?'
), td( textfield( 'name' ))),
Tr( td( 'ÃïéÜ åßíáé ç ãíþìç óïõ ãéá ôçí åõ÷ïýëá
»Êýñéå Éçóïý ×ñéóôÃ, ÅëÃçóïí Ìå« ?'
), td( textarea( -name=>'pray', -rows=>4, -columns=>25 ))),
Tr( td( 'ÃåñéÃãñáøå ìáò ìéá ðñïóùðéêÞ óïõ
ðíåõìáôéêÞ åìðåéñßá áðü êÜðïéïí ãÃñïíôá ðñïò
þöåëïò ôùí õðïëïßðùí áäåëöþí ( áí öõóéêÜ Ã÷åéò
:)' ), td( textarea( -name=>'remark', -rows=>6, -columns=>25 ))),
Tr( td( 'Ãïéü åßíáé ôï email óïõ?'
), td( textfield( 'email' ))),
Tr( td( submit( 'ÅìöÜíéóç üëùí ôùí áðüøåùí'
)), td( submit( 'ÃðïóôïëÞ' ))),
);
print end_form();
print br() x 2;

open(FILE, "<../data/text/tips") or die $!;
my @tips = <FILE>;
close(FILE);

@tips = grep { !/^\s*$/ } @tips;
my $tip = $tips[ rand @tips ];

print table( {class=>'info'}, Tr( td( {class=>'tip'}, $tip ))), br();

$sth = $dbh->prepare( $sql{update_counter} ) if ($host ne "Ãßêïò");
$sth->execute;

$sth = $dbh->prepare( $sql{get_counter} );
$sth->execute;

while ($row = $sth->fetchrow_hashref)
{
$counter += $row->{counter};
}

print table( {class=>'info'},
Tr( td( {class=>'host'}, $host )),
Tr( td( {class=>'date'}, $date )),
Tr( td( {class=>'counter'}, $counter ))
);

print br(), a( {href=>'games.pl'},
img{src=>'../data/images/games.gif'} );
print p( {-align=>'right'}, a( {href=>'show.pl?name=showlog'}, font(
{-size=>2, -color=>'Lime'}, b( 'Last Update: 30/4/2005' ))));
 
N

Nikos

Tassilo v. Parseval wrote:

Also i didnt quite understand what are you tryign to say here!
Can you please clarify it to em some more?

As you want shorter code, here's one way:

s/\n/\\n/g,
s/"/\\"/g ,
tr/\cM//d ,
for $data;
 
T

Tad McClellan

Nikos said:
I dont know what to do with the long lines you said...


Errr, make them shorter, what else?

print start_html( -style=>'/data/css/style.css', -title=>'Øõ÷ùöåëÞ
ÐíåõìáôéêÜ Êåßìåíá!', -background=>'/data/images/night.gif' );


print start_html( -style=>'/data/css/style.css',
-title=>'Øõ÷ùöåëÞÐíåõìáôéêÜ Êåßìåíá!',
-background=>'/data/images/night.gif' );

print p( {-align=>'center'}, font( {class=>'tip'}, 'ÄéÜëåîå Ýíá
áðü ôá êåßìåíá ãéá íá äéáâÜóåéò => ' ),
popup_menu( -name=>'select',
-values=>\@display_files ),
submit('ÅðéëïãÞ'));


print p( {-align=>'center'},
font( {class=>'tip'}, 'ÄéÜëåîå Ýíááðü ôá êåßìåíá '
. 'ãéá íá äéáâÜóåéò => ' ),
popup_menu( -name=>'select', -values=>\@display_files ),
submit('ÅðéëïãÞ'));


Viola! No word-wrapping.
 
B

Brian McCauley

Nikos said:
Also maybe thre is a better wau to create the $data variable instead of
constant concatenations as i have it.

You mean like where you say:

$data = "Charset I lack " .$host. "! more stuff";

Well it's more ideomatic to use interpolation:

$data = "Charset I lack $host! more stuff";
$sth = $dbh->prepare( $sql{update_visitor} );
$sth->execute($host);

Since you don't use that statment handle again after the execute() you
may want to condisder the shorthand form:

$dbh->do( $sql{update_visitor}, {}, $host);
else
{
if ($host ne "Ãßêïò")
{

You may want to consider elsif (that's not a typo, there really is no
'e' in Perl's spelling of 'elseif').
 
T

Tassilo v. Parseval

Also sprach Nikos:
Tassilo v. Parseval wrote:

You should use quotation marks to indicate which parts I wrote and which
were yours.
Also i didnt quite understand what are you tryign to say here!
Can you please clarify it to em some more?

[quotations inserted for clearity]

This is functionally equivalent to what you've written, which was:

$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;

By using 'for $data', $data gets aliased to $_ which is the default
variable that s/// and tr/// act upon. By using 'for' as a
statement-modifier (that is: in postfix notation) no block is needed
which would normally be the case if you wrote:

for ($data) {
s/\n/\\n/g;
s/"/\\"/g;
tr/\cM//d;
}

Tassilo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top