Looping (continued)

N

Nikos

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.
 
N

Nikos

Nikos 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
 
M

Mark Clements

Nikos said:
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
 
M

Mark Clements

Nikos said:
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;
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
 
T

Tad McClellan

Nikos said:
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.
 
J

Joe Smith

Nikos said:
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
 

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

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top