Code Comments
Programming Forum and web based access to our favorite programming groups.ok before we go into the step i asked i must somehow load the games
database table with a row coantaining 3 fields. The games name, the
games description and the number of times the games downloaded by the user.
I had the table loaded with repetitive insert into statements but now
the games folder has more than 100+ games so i need a more automatic way
of filling it in.
I have made the following snippet of code but as usual it aint working
as it should so i could use a liitle Monk help/suggestions. After
completeing this part i will go to the one i first asked because now
that i deleted the insert into statements i must firstly load the
database table again Any way here is the code so far:
It would be even better that the description of the game would not be
the same text as the name of the game that why i have wriiten all the
description in one file in the same folder as games separating by one
line but i donw know hot to load them as a 2nd parameter to the 2nd ? in
prepare. Any way here is the code so far:
$db->do( "create table games( name varchar, desc text, counter int"
+);
#=======================================
==============================
+==========
my $st = $db->prepare( "INSERT INTO games VALUES (?, ?, ?)" );
my @games = glob( "/data/games/*" ) or die $!;
print @games;
while (@games) {
$st->execute( $_, $_, 0 );
}
#=======================================
==============================
+==========
# hre is the part that load the description game into an array from a
+file containign the descs
open(FILE, "</data/games/descriptions.txt") or die $!;
my @desc = <FILE>;
close(FILE);
@desc = grep { !/^\s*\z/s } @desc;
Post Follow-up to this messageIn article <d4jfiu$83d$1@nic.grnet.gr>, Nikos <hackeras@gmail.com>
wrote:
> ok before we go into the step i asked i must somehow load the games
> database table with a row coantaining 3 fields. The games name, the
> games description and the number of times the games downloaded by the user
.
>
> I had the table loaded with repetitive insert into statements but now
> the games folder has more than 100+ games so i need a more automatic way
> of filling it in.
>
> I have made the following snippet of code but as usual it aint working
> as it should so i could use a liitle Monk help/suggestions. After
> completeing this part i will go to the one i first asked because now
> that i deleted the insert into statements i must firstly load the
> database table again Any way here is the code so far:
>
> It would be even better that the description of the game would not be
> the same text as the name of the game that why i have wriiten all the
> description in one file in the same folder as games separating by one
> line but i donw know hot to load them as a 2nd parameter to the 2nd ? in
> prepare.
Put your game names and descriptions in a separate file, one game on
each line. Put the name first followed by a tab character followed by
the description, making sure that the description does not contain any
tabs. Read these descriptions into a hash with the following code
(untested):
my %descriptions;
open( my $desc, '<', 'descriptions.txt' ) or
die("Can't open descriptions file: $!");
while(<$desc> ) {
chomp;
my( $name, $description ) = split(/\t/);
$descriptions{$name} = $description;
}
> Any way here is the code so far:
>
> $db->do( "create table games( name varchar, desc text, counter int"
> +);
>
>
> #=======================================
==============================
> +==========
>
> my $st = $db->prepare( "INSERT INTO games VALUES (?, ?, ?)" );
> my @games = glob( "/data/games/*" ) or die $!;
>
> print @games;
>
> while (@games) {
> $st->execute( $_, $_, 0 );
Make the above line
$st->execute( $_, $descriptions{$_}, 0 );
and you are done.
> }
>
> #=======================================
==============================
> +==========
>
> # hre is the part that load the description game into an array from a
> +file containign the descs
>
> open(FILE, "</data/games/descriptions.txt") or die $!;
> my @desc = <FILE>;
> close(FILE);
>
> @desc = grep { !/^\s*\z/s } @desc;
----== Posted via mcse.ms - Unlimited-Uncensored-Secure Usenet News==-
---
http://www.mcse.ms The #1 Newsgroup Service in the World! >100,000 New
sgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Post Follow-up to this messageNikos wrote: > I have made the following snippet of code but as usual it aint working > as it should You really think people are going to complete your script, set up a database, and fix it? Which error do you get? Or what is the behavior you see? -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html
Post Follow-up to this messageJim Gibson wrote:
> Put your game names and descriptions in a separate file, one game on
> each line. Put the name first followed by a tab character followed by
> the description, making sure that the description does not contain any
> tabs. Read these descriptions into a hash with the following code
> (untested):
>
> my %descriptions;
> open( my $desc, '<', 'descriptions.txt' ) or
> die("Can't open descriptions file: $!");
> while(<$desc> ) {
> chomp;
> my( $name, $description ) = split(/\t/);
> $descriptions{$name} = $description;
> }
Thanks but i was wondering/thinking that there is no need actually to
put except from the descriptions also the name of the games inside the
description file since we can get all the games names from the game
folder they are inside by doing this:
my @games = </data/games/*.rar> or die $!;
What do you think?
Post Follow-up to this messageNikos <hackeras@gmail.com> wrote:
>
> while (@games) {
> $st->execute( $_, $_, 0 );
> }
This looks like an infinite loop to me.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Post Follow-up to this messagexhoster@gmail.com wrote:
> Nikos <hackeras@gmail.com> wrote:
>
Actually now is changed to:
$db->do( "create table games( onoma text, description text, counter
int )" ) or die $!;
#=======================================
====================================
====
my %descriptions;
open( my $desc, "</data/games/perigrafes.txt" ) or die $!;
while(<$desc> ) {
chomp;
my( $name, $description ) = split(/\t/);
$descriptions{$name} = $description;
}
my $st = $db->prepare( "INSERT INTO games VALUES (?, ?, ?)" );
my @games = </data/games/*.rar> or die $!;
while (@games) {
$st->execute( $_, $descriptions{$_}, 0 );
}
#=======================================
====================================
====
And here si the code that tries to displays those database table values
in a esy appelaing way:
my $row;
while ( $row = $st->fetchrow_hashref ) {
print table( {class=>'info'},
Tr(
td( submit( -name=>'game', -value=>$_->{name} )),
td( $_->{description} ),
td( $_->{counter} )
)
)
}
But it aint show anyhting :(
Post Follow-up to this messageNikos wrote:
>
> Actually now is changed to:
>
Irrelevant. You should heed Xho's advice.
>
> while (@games) {
> $st->execute( $_, $descriptions{$_}, 0 );
> }
This is still an infinite loop. Change the while to for.
Post Follow-up to this messageNikos wrote:
> Actually now is changed to:
>
> $db->do( "create table games( onoma text, description text, counter
> int )" ) or die $!;
>
You still aren't partitioning your problem.
>
> #=======================================
==================================
======
>
>
> my %descriptions;
> open( my $desc, "</data/games/perigrafes.txt" ) or die $!;
>
> while(<$desc> ) {
> chomp;
> my( $name, $description ) = split(/\t/);
> $descriptions{$name} = $description;
> }
>
> my $st = $db->prepare( "INSERT INTO games VALUES (?, ?, ?)" );
>
> my @games = </data/games/*.rar> or die $!;
>
Does @games contain what you think it contains at this stage? Have you
checked?
> while (@games) {
> $st->execute( $_, $descriptions{$_}, 0 );
> }
This will only ever complete if @games is empty....
How many elements does @games contain? Have you tried Data::Dumper?
Do you check the return value of $st->execute()?
Following this, what is in the database table? Have you used the mysql
console to execute
select * from games;
Until you verify that the data is as you expect, then there is little
point in worrying about the next step....
> #=======================================
==================================
======
>
>
>
> And here si the code that tries to displays those database table values
> in a esy appelaing way:
>
> my $row;
> while ( $row = $st->fetchrow_hashref ) {
>
> print table( {class=>'info'},
> Tr(
> td( submit( -name=>'game', -value=>$_->{name} )),
> td( $_->{description} ),
> td( $_->{counter} )
> )
> )
> }
This is going to give you a separate table for each row.
Mark
Post Follow-up to this messageNikos <hackeras@gmail.com> wrote:
> xhoster@gmail.com wrote:
You snipped everything that Xho wrote.
he said that this:
looked like an infinite loop.
> while (@games) {
> $st->execute( $_, $descriptions{$_}, 0 );
> }
And it *still* looks like an infinite loop.
This is precisely why some folks have given up on helping you,
a problem was pointed out to you, but you didn't fix it.
We get the feeling that you are not listening to followups,
so there isn't much point it spending time composing
a followup.
Fix your infinite loop.
> my $row;
> while ( $row = $st->fetchrow_hashref ) {
>
> print table( {class=>'info'},
> Tr(
> td( submit( -name=>'game', -value=>$_->{name} )),
> td( $_->{description} ),
> td( $_->{counter} )
> )
> )
> }
>
> But it aint show anyhting :(
Look at the name of the hashref variable.
Look at the name of the variable that you are using as if it
was a hashref.
Do they look like the same variable?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Post Follow-up to this messageTad McClellan wrote:
>while (@games) {
> $st->execute( $_, $descriptions{$_}, 0 );
>}
for (@games) {
$st->execute( $_, $descriptions{$_}, 0 );
}
but still for soem reason the database table games aint loading.
data::dumper says its empty.
But it should have been loading.
>my $row;
>while ( $row = $st->fetchrow_hashref ) {
>
> print table( {class=>'info'},
> Tr(
> td( submit( -name=>'game', -value=>$_->{name} )),
> td( $_->{description} ),
> td( $_->{counter} )
> )
> )
>}
my $st = $db->prepare( "SELECT * FROM games" );
$st->execute();
while ( $st->fetchrow_hashref ) {
print table( {class=>'info'},
Tr(
td( submit( -name=>'game', -value=>$_->{name} )),
td( $_->{description} ),
td( $_->{counter} )
)
)
}
Yes i removed @row because as i had it it didnt compare
$row and $st->fetchrow_hashref but instead it assigned values to #row,
so i completed remove $row.
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.