Code Comments
Programming Forum and web based access to our favorite programming groups.Hello i still cant make this work:
$st = $db->prepare( "SELECT * FROM counter" );
$st->execute();
my @tableRows;
while ( my $row = $st->fetchrow_hashref() ) {
push @tableRows, $row;
}
print table( {class=>'info'},
map {
Tr(
td( submit( -name=>'game', -value=>$_->{name} )),
td( $_->{text} ),
td( $_->{name} )
)
} @tableRows
);
I only got 1 row with 3 fileds one having a button saying game and
beside it 2 empty cells instead of the big game list i was producing
with the print statements before i turn it to loop.
Post Follow-up to this messageNikos wrote:
Please can someone make this work?
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
use DBD::mysql;
my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
my $xronos = "$mday $months[$mon], $hour:$min";
my $game = param('game');
my $ip = $ENV{'REMOTE_ADDR'};
my @numbers = split (/\./,$ip);
my $address = pack ("C4", @numbers);
my $host = gethostbyaddr ($address, 2) || $ip;
print header( -charset=>'iso-8859-7' );
print start_html( -style=>'../style.css', -title=>'Ðáé÷_éäÜêéá ê
áé ü÷é
ìü_ï!', -background=>'../data/images/night.gif' );
my $db = ($ENV{'SERVER_NAME'} ne 'nikolas.50free.net')
? DBI->connect('DBI:mysql:nikos_db', 'root', '')
: DBI->connect('DBI:mysql:nikos_db:50free.net', 'nikos_db',
'tiabhp2r')
or print font({-size=>5, -color=>'Lime'}, $DBI::errstr) and exit 0;
print p( font( {-size=>4, -color=>'Lime'}, "Áðü åäþ ìðïñåßò _
á
êáôåâÜóåéò ðáé÷_ßäéá üðùò åðßóçò êáé äéê
ìïõ ðñïãñÜììáôá:<br>" ),
font( {-size=>4, -color=>'Lime'}, "ÃñÜøå ìïõ
ôéò å_ôõðþóåéò óïõ óôï "),
font( {-size=>4, -color=>'White'},
"nik0s\@mycosmos.gr<br><br>" ));
print start_form(-action=>'games.pl');
my $st = $db->prepare( "SELECT * FROM counter" );
$st->execute();
my @tableRows;
while ( my $row = $st->fetchrow_hashref() ) {
push @tableRows, $row;
}
print table( {class=>'info'},
map {
Tr(
td( submit( -name=>'game', -value=>$_->{name} )),
td( $_->{text} ),
td( $_->{name} )
)
} @tableRows
);
print '<br>';
if ( !param() ) { print p( a( {href=>'index.pl'}, img
{src=>'../data/images/back.gif'} )); }
if ( param() )
{
$db->do( "UPDATE counter SET $game = $game + 1" );
$st = $db->prepare( "SELECT $game FROM counter" );
$st->execute();
$row = $st->fetchrow_hashref;
print p( font( {-size=>4, -color=>'Yellow'}, "Åßóáé ï " ),
font( {-size=>4, -color=>'White'},
"$row->{$game}" ),
font( {-size=>4, -color=>'Yellow'},
"ïò ðïõ êáôåâÜæåé ôï " ),
font( {-size=>4, -color=>'White'},
"$game!<br>" ),
font( {-size=>4, -color=>'Yellow'},
"Åëðßæù _á óïõ áñÝóåé êáé _á óïõ öá_åß ÷ñÞ
éìï!" ));
$db->do( "UPDATE logs SET keimeno='$game' WHERE host='$host'" ) or
die $db->errstr;
print p( a( {href=>'index.pl'}, img
{src=>'../data/images/back.gif'} ));
print "<script
language='Javascript'>location.href='../data/games/$game.rar'</script>";
}
Iam getting thsi when i try to run it:
Global symbol "$sec" requires explicit package name at D:\www\cgi-bin\
+games.pl line 9.
Global symbol "$min" requires explicit package name at D:\www\cgi-bin\
+games.pl line 9.
Global symbol "$hour" requires explicit package name at D:\www\cgi-bin
+\games.pl line 9.
Global symbol "$mday" requires explicit package name at D:\www\cgi-bin
+\games.pl line 9.
Global symbol "$mon" requires explicit package name at D:\www\cgi-bin\
+games.pl line 9.
Global symbol "$year" requires explicit package name at D:\www\cgi-bin
+\games.pl line 9.
Global symbol "$wday" requires explicit package name at D:\www\cgi-bin
+\games.pl line 9.
Global symbol "$yday" requires explicit package name at D:\www\cgi-bin
+\games.pl line 9.
Global symbol "$isdst" requires explicit package name at D:\www\cgi-bi
+n\games.pl line 9.
Global symbol "$mday" requires explicit package name at D:\www\cgi-bin
+\games.pl line 10.
Global symbol "$mon" requires explicit package name at D:\www\cgi-bin\
+games.pl line 10.
Global symbol "$hour" requires explicit package name at D:\www\cgi-bin
+\games.pl line 10.
Global symbol "$min" requires explicit package name at D:\www\cgi-bin\
+games.pl line 10.
Global symbol "$row" requires explicit package name at D:\www\cgi-bin\
+games.pl line 62.
Global symbol "$row" requires explicit package name at D:\www\cgi-bin\
+games.pl line 65.
Execution of D:\www\cgi-bin\games.pl aborted due to compilation errors
Post Follow-up to this messageNikos wrote:
> Hello i still cant make this work:
>
> $st = $db->prepare( "SELECT * FROM counter" );
> $st->execute();
>
> my @tableRows;
> while ( my $row = $st->fetchrow_hashref() ) {
> push @tableRows, $row;
> }
>
> print table( {class=>'info'},
> map {
> Tr(
> td( submit( -name=>'game', -value=>$_->{name} )),
> td( $_->{text} ),
> td( $_->{name} )
> )
> } @tableRows
> );
>
> I only got 1 row with 3 fileds one having a button saying game and
> beside it 2 empty cells instead of the big game list i was producing
> with the print statements before i turn it to loop.
I've said this before: it looks like I will have to say it again. *What*
is in @tableRows following the while loop that populates it? As I have
also said before, you can use Data::Dumper to examine the contents of
data structures.
use Data::Dumper;
....
warn Dumper \@tableRows;
will dump the contents of @tableRows to the console if you run the
script from the command line.
Sigh.
Mark
Post Follow-up to this messageNikos wrote: > Nikos wrote: > Please can someone make this work? <snip> No. We don't have access to your environment. You have to learn to debug your own programs. > ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime; <snip> > Global symbol "$sec" requires explicit package name at D:\www\cgi-bin\ > +games.pl line 9. <snip error messages on this theme> As the documentation for strict perldoc strict states, your variables need to be declared before use, typically with my. Is any of this getting through? Mark
Post Follow-up to this messageNikos <hackeras@gmail.com> wrote: > Please can someone make this work? Please post your job offers in a newsgroup for job offers, or advertise on the perl-jobs mailing list. -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas
Post Follow-up to this messageNikos wrote:
> my @months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
> 'Sep', 'Oct', 'Nov', 'Dec');
It appears that you are using an out-of-date book for a reference.
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime;
The fix for that line is to simply add two characters to it.
-Joe
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.