Looping (continued)

Discussion in 'Perl Misc' started by Nikos, Apr 23, 2005.

  1. Nikos

    Nikos Guest

    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.
     
    Nikos, Apr 23, 2005
    #1
    1. Advertising

  2. Nikos

    Nikos Guest

    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
     
    Nikos, Apr 23, 2005
    #2
    1. Advertising

  3. Nikos 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
     
    Mark Clements, Apr 23, 2005
    #3
  4. Nikos 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
     
    Mark Clements, Apr 23, 2005
    #4
  5. Nikos <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 23, 2005
    #5
  6. Nikos

    Joe Smith Guest

    Nikos 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
     
    Joe Smith, Apr 25, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Dupont
    Replies:
    1
    Views:
    372
    Lloyd Dupont
    Sep 30, 2004
  2. Lloyd Dupont
    Replies:
    1
    Views:
    439
    Guest
    Dec 22, 2004
  3. =?Utf-8?B?S2lzaG9yZSBHb3BhbGFu?=

    (continued...System.Security.SecurityException

    =?Utf-8?B?S2lzaG9yZSBHb3BhbGFu?=, Oct 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    380
  4. joel s
    Replies:
    0
    Views:
    307
    joel s
    Nov 3, 2003
  5. Replies:
    5
    Views:
    304
Loading...

Share This Page