[23827] in Perl-Users-Digest
Perl-Users Digest, Issue: 6030 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 21:21:14 2004
Date: Thu, 29 Jan 2004 18:15:43 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 Jan 2004 Volume: 10 Number: 6030
Today's topics:
Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? ctcgag@hotmail.com
Re: Can someone tell me what is wrong with this? <cpryce@nospam.pryce.net>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <xx087@freenet.carleton.ca>
Re: Can someone tell me what is wrong with this? (G Klinedinst)
Re: Can someone tell me what is wrong with this? ctcgag@hotmail.com
Re: Can someone tell me what is wrong with this? <gnari@simnet.is>
Re: Can someone tell me what is wrong with this? <dwall@fastmail.fm>
Re: Can someone tell me what is wrong with this? ctcgag@hotmail.com
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <bigswifty00000@yahoo.com>
Re: Can someone tell me what is wrong with this? <dwall@fastmail.fm>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 29 Jan 2004 15:33:26 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Can someone tell me what is wrong with this?
Message-Id: <Xns947F6B850158Ckburdishoptonlinenet@167.206.3.2>
I can't seem to find any examples that look like what I'm doing, so I'm
sure I'm doing it wrong!!!
I get back some rows from the database, and then want to put those values
in checkboxes that if selected, will be then be used to select specific
rows from another table.
The first line works with the variables, but the checkbox line does not!!
I tried quoting and unquoting and requoting etc etc!!!
Where am I going wrong???
THANKS IN ADVANCE!!!
BIG SWIFTY
........
foreach (@documents) {
($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
[$counter+1], $documents[$counter+2];
print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
# PREVIOUS LINE WORKS
print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
$doc_name);
# NOT LINE ABOVE
$counter ++;
}
------------------------------
Date: 29 Jan 2004 16:30:06 GMT
From: ctcgag@hotmail.com
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <20040129113006.972$CF@newsreader.com>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> I can't seem to find any examples that look like what I'm doing, so I'm
> sure I'm doing it wrong!!!
> I get back some rows from the database,
If it's worth telling us in English, it's worth telling is in Perl.
(If we need to know they came from a database, show us that you get them
from the database. If we don't need to know, we don't need to know!)
> and then want to put those values
> in checkboxes that if selected, will be then be used to select specific
> rows from another table.
> The first line works with the variables, but the checkbox line does not!!
> I tried quoting and unquoting and requoting etc etc!!!
> Where am I going wrong???
When you say it does not work, what do you mean? It doesn't compile? It
throws a runtime error? Your computer catches fire?
>
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
You seem to be incoherently mixing an iterator "for" loop with a index
method. You didn't show us how/with what @documents is populated, so I
can't tell you how to do it right, but you are surely doing it wrong.
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
This line seems to do exactly what it is supposed to do.
> # NOT LINE ABOVE
> $counter ++;
Whatever @documents is, it is playing role-playing games. Any given element
will sometimes by a doc_id, sometimes a doc_name, sometimes a score.
> }
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Thu, 29 Jan 2004 10:51:48 -0600
From: cp <cpryce@nospam.pryce.net>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <290120041051483796%cpryce@nospam.pryce.net>
In article <Xns947F6B850158Ckburdishoptonlinenet@167.206.3.2>, Big
Swifty <bigswifty00000@yahoo.com> wrote:
> sure I'm doing it wrong!!!
> I get back some rows from the database, and then want to put those values
> in checkboxes that if selected, will be then be used to select specific
> rows from another table.
> The first line works with the variables, but the checkbox line does not!!
Do you go to the doctor and mutter, "I'm not feeling so well?" And
then, not give enough specifics for a diagnosis?
Define 'does not work'? What did you expect it to do. What did it do
instead? Did it produce an error or warning ?
> I tried quoting and unquoting and requoting etc etc!!!
> Where am I going wrong???
>
>
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
you're looping through each item in an array. Then you're using the
first three elements of that array each iteration, offest by one each
time you loop through. Not, I think, what you have in mind. And I'm not
sure why you're using those variables anyway. If all your going to do
is assign it to values of a CGI fucntion call?
What is actually in @documents? If it is the result of a database
query, is it perhaps an array of arrayrefs?
Generally, if you have the results of a database query in an array of
array refs, you would want a loop lik :
# untested
foreach my $row ( @documents ) {
print qq(<PRE><TT><B>$row->[0] $row->[1] $row->[2]</B></TT></PRE>),
$q->checkbox(-name=>$row->[0],-value=>'YES',
-label=>$row->[0] );
}
or a more idiomatic version, eliminating the array in the first place
# prepare and execute a query,
my $sth = $dbh->prepare( $some_sql_statement );
$sth->execute();
# more untested code
my $row;
while ( $row = $sth->fetchrow_arrayref() ) {
print qq(<PRE><TT><B>$row->[0] $row->[1] $row->[2]</B></TT></PRE>),
$q->checkbox(-name=>$row->[0],-value=>'YES',
-label=>$row->[0] );
}
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
Define 'works'
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
> # NOT LINE ABOVE
define 'Not line above'
> $counter ++;
> }
--
cp
------------------------------
Date: Thu, 29 Jan 2004 18:19:03 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F87982E6ADkburdishoptonlinenet@167.206.3.3>
Big Swifty <bigswifty00000@yahoo.com> wrote in
news:Xns947F6B850158Ckburdishoptonlinenet@167.206.3.2:
> I can't seem to find any examples that look like what I'm doing, so
> I'm sure I'm doing it wrong!!!
> I get back some rows from the database, and then want to put those
> values in checkboxes that if selected, will be then be used to select
> specific rows from another table.
> The first line works with the variables, but the checkbox line does
> not!! I tried quoting and unquoting and requoting etc etc!!!
> Where am I going wrong???
>
>
> THANKS IN ADVANCE!!!
>
>
> BIG SWIFTY
>
>
> ........
>
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
> # NOT LINE ABOVE
> $counter ++;
> }
Sorry, I should know better, it's out of frustration, and embarassment at
being new at Perl, Oracle, HTML and CGI!!!!! The code is full of
commented tried this and that stuff VERY UGLY so I just included what I
thought was relevant!!
Thanks for trying to answer my vague question anyway!!!
I have this CGI script, which I am retrieving values from an Oracle
database. These values are put into @documents which I am then looping
through to extract 3 values for each row; doc_id, doc_name and score.
The problem is I don't know how to handle the variables in the html.
I see a checkbox but no label. If I look at the source the checkbox name
is "". I tried quoting $doc_name, unquoting etc etc.
yet in the line
print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
the value for the variable prints correctly.
I will go back now and look at your suggestions,
In the meantime :
(this seems to be working based on the line that does print correctly)
sub select {
undef @documents;
$sth = $dbh->prepare("SELECT doc_id,doc_name, SCORE(1) score FROM
mydocuments WHERE CONTAINS(document, ?, 1) > 0
order by score desc")
or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
$sth->execute($form_vars{'01_text'}) or die "Can't execute
SQL statement: ", $sth->errstr(), "\n";
while (@row = $sth->fetchrow_array ) {
push (@documents,"$row[0] $row[1] $row[2] ");
}
return @documents;
}
Then I start generating HTML
print $q->header ( "text/html"),
$q->start_html( -title => "Thank you", -bgcolor => "#CCFFCC"),
$q->h2("Thank you" ),
$q->b( "$timestamp" ),
$q->p(),
$q->b("Your search was for: $form_vars{'01_text'}"),
$q->hr;
Then this:
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
> # NOT LINE ABOVE
> $counter ++;
> }
Then:
print <<"EOF";
<P>Return to
<A HREF="$site_url">$site_name</A>.</P>
<!-- comment -->
</BODY>
</HTML>
EOF
------------------------------
Date: Thu, 29 Jan 2004 18:31:28 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F89B28740Bkburdishoptonlinenet@167.206.3.3>
Hi Xho:
Can you tell me what you mean by this?
You seem to be incoherently mixing an iterator "for" loop with a index
> method. You didn't show us how/with what @documents is populated, so
> I can't tell you how to do it right, but you are surely doing it
> wrong.
I sent back a reply to my 1st message showing the code to retrieve
3 columns n rows of data from Oracle db, places into @documents. I use
the counter to pull back rows and the variables to store the columns.
Any suggestion on how to do this better would definitely be appreciated!!
foreach (@documents) {
($doc_id,$doc_name,$score) = $documents[$counter+0],
$documents [$counter+1], $documents[$counter+2];
print "<PRE><TT><B>$doc_id $doc_name
>> $score</B></TT></PRE>";
>> # PREVIOUS LINE WORKS
>> print $q->checkbox (-name =>$doc_name,-value => "YES", -label
>> =>
>> $doc_name);
Thanks!!!
------------------------------
Date: Thu, 29 Jan 2004 18:46:39 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F8C458A0E0kburdishoptonlinenet@167.206.3.3>
Hi CP:
Please see apologies in other posts!!!
>
> you're looping through each item in an array. Then you're using the
> first three elements of that array each iteration, offest by one each
> time you loop through. Not, I think, what you have in mind. And I'm
> not sure why you're using those variables anyway. If all your going to
> do is assign it to values of a CGI fucntion call?
>
I am trying to put the results of an SQL query doc_id, doc_name, score
into a checkbox list that I will let user check if they want to see the
doc.
> What is actually in @documents? If it is the result of a database
> query, is it perhaps an array of arrayrefs?
(this seems to be working based on the line that does print correctly)
sub select {
undef @documents;
$sth = $dbh->prepare("SELECT doc_id,doc_name, SCORE(1) score FROM
mydocuments WHERE CONTAINS(document, ?, 1) > 0
order by score desc")
or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
$sth->execute($form_vars{'01_text'}) or die "Can't execute
SQL statement: ", $sth->errstr(), "\n";
while (@row = $sth->fetchrow_array ) {
push (@documents,"$row[0] $row[1] $row[2] ");
}
return @documents;
}
>
> Generally, if you have the results of a database query in an array of
> array refs, you would want a loop lik :
>
Since I am new to virtually all of this (Oracle, HTML,CGI, Perl) I try
taking it step by step so I know where things are going wrong. I realize
I can combine the database access with generating the HTML, but for now I
would like to keep it separate. (also in case I want to do something else
with the returned data)
> # untested
> foreach my $row ( @documents ) {
> print qq(<PRE><TT><B>$row->[0] $row->[1]
> $row->[2]</B></TT></PRE>),
> $q->checkbox(-name=>$row->[0],-value=>'YES',
> -label=>$row->[0] );
> }
>
> or a more idiomatic version, eliminating the array in the first place
> # prepare and execute a query,
> my $sth = $dbh->prepare( $some_sql_statement );
> $sth->execute();
>
> # more untested code
> my $row;
> while ( $row = $sth->fetchrow_arrayref() ) {
> print qq(<PRE><TT><B>$row->[0] $row->[1]
> $row->[2]</B></TT></PRE>),
> $q->checkbox(-name=>$row->[0],-value=>'YES',
> -label=>$row->[0] );
> }
>
>
>> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
>> # PREVIOUS LINE WORKS
>
> Define 'works'
>> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
>> $doc_name);
>> # NOT LINE ABOVE
>
> define 'Not line above'
>
>> $counter ++;
>> }
>
------------------------------
Date: 29 Jan 2004 18:48:51 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <slrnc1ilck.r08.xx087@smeagol.ncf.ca>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> while (@row = $sth->fetchrow_array ) {
> push (@documents,"$row[0] $row[1] $row[2] ");
> }
[...]
> > foreach (@documents) {
> > ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> > [$counter+1], $documents[$counter+2];
You probably want:
while (@row = $sth->fetchrow_array) {
push @documents, [@row];
}
...
foreach my $rowref (@documents) {
my ($doc_id,$doc_name,$score) = @$rowref;
...
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: 29 Jan 2004 10:54:02 -0800
From: g_klinedinst@hotmail.com (G Klinedinst)
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <168f035a.0401291054.117b0d42@posting.google.com>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> foreach (@documents) {
> ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> [$counter+1], $documents[$counter+2];
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> # PREVIOUS LINE WORKS
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> $doc_name);
> # NOT LINE ABOVE
> $counter ++;
> }
First can you show us how you are populating @documents(the code).
Also can you show us the code where you are initializing $q? Is
@documents a multi-dimensional array?
My first question is why you are iterating thru @documents, keeping a
counter, and then using $counter, $counter+1 andn $counter+2 to refer
to elements of the array? It would seem like if you had an array of
the numbers 1-10 printed out what you are doing you would get:
1 2 3
2 3 4
3 4 5
4 5 6
etc.
I can't imaging that is what you are trying to do. I'll go out on a
limb here and say you probably need to be looping through a record set
rather than an array. If you post more details I imagine someone here
can help you. I'll certainly try although I am not too familiar with
the Perl HTML objects.
-Greg
------------------------------
Date: 29 Jan 2004 18:59:50 GMT
From: ctcgag@hotmail.com
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <20040129135950.858$M8@newsreader.com>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> >
> > foreach (@documents) {
> > ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> > [$counter+1], $documents[$counter+2];
> > print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> > # PREVIOUS LINE WORKS
> > print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>
> > $doc_name);
> > # NOT LINE ABOVE
> > $counter ++;
> > }
Ok, I think I see now. You think the print works because $doc_id contains
all three values that you want, and the other two are empty (or contain
data for the next things, I'm not sure which). If you used strict and
warnings, Perl would probably explain this to you.
> Sorry, I should know better, it's out of frustration, and embarassment at
> being new at Perl, Oracle, HTML and CGI!!!!! The code is full of
> commented tried this and that stuff VERY UGLY so I just included what I
> thought was relevant!!
>
> Thanks for trying to answer my vague question anyway!!!
>
> I have this CGI script, which I am retrieving values from an Oracle
> database. These values are put into @documents which I am then looping
> through to extract 3 values for each row; doc_id, doc_name and score.
> The problem is I don't know how to handle the variables in the html.
Nope, the problem occurs before that.
> I see a checkbox but no label. If I look at the source the checkbox name
> is "". I tried quoting $doc_name, unquoting etc etc.
>
> yet in the line
>
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
>
> the value for the variable prints correctly.
Not really. Change that line to:
print
"<PRE><TT><B>|||||$doc_id|||||||$doc_name||||$score||||</B></TT></PRE>";
And see what get's printed.
> sub select {
> undef @documents;
don't do that. use strict and my.
> $sth = $dbh->prepare("SELECT doc_id,doc_name, SCORE(1) score FROM
> mydocuments WHERE CONTAINS(document, ?, 1) > 0
> order by score desc")
> or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
> $sth->execute($form_vars{'01_text'}) or die "Can't
> execute SQL statement: ", $sth->errstr(), "\n";
>
> while (@row = $sth->fetchrow_array ) {
> push (@documents,"$row[0] $row[1] $row[2] ");
What do you think this is doing? Is it adding one thing to @documents,
or is it adding 3 things to @documents?
> }
> return @documents;
> }
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Thu, 29 Jan 2004 18:50:45 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <bvbkrp$6c5$1@news.simnet.is>
"Big Swifty" <bigswifty00000@yahoo.com> wrote in message
news:Xns947F89B28740Bkburdishoptonlinenet@167.206.3.3...
> Hi Xho:
>
> Can you tell me what you mean by this?
>
>
> You seem to be incoherently mixing an iterator "for" loop with a index
> > method. You didn't show us how/with what @documents is populated, so
> > I can't tell you how to do it right, but you are surely doing it
> > wrong.
> foreach (@documents) {
here you are iterating through @documents, each pass one
element of @documents is in $_
> ($doc_id,$doc_name,$score) = $documents[$counter+0],
> $documents [$counter+1], $documents[$counter+2];
but here you are refering to $counter as if it is a loop index
very confusing
and what's more quoting here from another post from you in this thread:
> while (@row = $sth->fetchrow_array ) {
> push (@documents,"$row[0] $row[1] $row[2] ");
> }
@documents seems to contain a set of strings concatenated from
your table columns
you MIGHT have meant to do something like:
while (@row = $sth->fetchrow_array ) {
push @documents, \@row;
}
and then :
foreach my $row (@documents) {
($doc_id,$doc_name,$score) = @$row;
}
but who knows?
gnari
------------------------------
Date: Thu, 29 Jan 2004 19:38:00 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F94DC06244dkwwashere@216.168.3.30>
Glenn Jackman <xx087@freenet.carleton.ca> wrote:
> Big Swifty <bigswifty00000@yahoo.com> wrote:
>> while (@row = $sth->fetchrow_array ) {
>> push (@documents,"$row[0] $row[1] $row[2] ");
>> }
> [...]
>> > foreach (@documents) {
>> > ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
>> > [$counter+1], $documents[$counter+2];
>
>
> You probably want:
> while (@row = $sth->fetchrow_array) {
> push @documents, [@row];
> }
> ...
> foreach my $rowref (@documents) {
> my ($doc_id,$doc_name,$score) = @$rowref;
> ...
"Big Swifty" is going to be building some simple data structures, so s/he
would also benefit from reading the following:
perldoc perllol
perldoc perldsc
and also
perldoc perlref
for more general info about references.
I also noticed that the code doesn't seem to have strictures and warnings
enabled, and looks as if it depends on global variables.
To "Big Swifty":
use strict;
use warnings;
should be at the beginning of all non-trivial programs (unless you have a
really good reason and know exactly why you're not enabling them).
Consider them essential safety equipment for detecting typos and other
careless mistakes.
For info about passing data into subroutines instead of using global
variables, see
perldoc perlsub
--
David Wall
------------------------------
Date: 29 Jan 2004 19:43:11 GMT
From: ctcgag@hotmail.com
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <20040129144311.108$Z7@newsreader.com>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> Hi Xho:
>
> Can you tell me what you mean by this?
>
> You seem to be incoherently mixing an iterator "for" loop with a index
> > method. You didn't show us how/with what @documents is populated, so
> > I can't tell you how to do it right, but you are surely doing it
> > wrong.
I'm not sure how else to explain it. when you use the construct
foreach (@documents) {
you are telling to to set $_ to each member of @documents in turn,
and run the body of the loop. You should be working with the contents of
$_, not explicitly with the elements @documents.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Thu, 29 Jan 2004 20:17:21 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F9BA4F34E3kburdishoptonlinenet@167.206.3.2>
Glenn Jackman <xx087@freenet.carleton.ca> wrote in
news:slrnc1ilck.r08.xx087@smeagol.ncf.ca:
> You probably want:
> while (@row = $sth->fetchrow_array) {
> push @documents, [@row];
> }
> ...
> foreach my $rowref (@documents) {
> my ($doc_id,$doc_name,$score) = @$rowref;
> ...
>
Glenn:
This worked!! I don't understand yet why, What do the brackets do in
[@row]
You are pushing the @row array on top of the @documents array. And then
dereferencing with @$rowref???
I'm still not sure why I was able to get values for all 3 variables in
this line but couldn't get $doc_name in next
print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>>
$doc_name);
On to the next ball buster!!
Thanks a mil to you and all that responded!!!
------------------------------
Date: Thu, 29 Jan 2004 20:27:34 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F9D60D543kburdishoptonlinenet@167.206.3.2>
"David K. Wall" <dwall@fastmail.fm> wrote in
news:Xns947F94DC06244dkwwashere@216.168.3.30:
> "Big Swifty" is going to be building some simple data structures, so
> s/he would also benefit from reading the following:
>
> perldoc perllol
> perldoc perldsc
>
> and also
>
> perldoc perlref
>
> for more general info about references.
>
> I also noticed that the code doesn't seem to have strictures and
> warnings enabled, and looks as if it depends on global variables.
>
> To "Big Swifty":
>
> use strict;
> use warnings;
>
> should be at the beginning of all non-trivial programs (unless you
> have a really good reason and know exactly why you're not enabling
> them). Consider them essential safety equipment for detecting typos
> and other careless mistakes.
>
> For info about passing data into subroutines instead of using global
> variables, see
>
> perldoc perlsub
>
All VERY helpful information, I know I am bypassing a lot of security, good
coding practices etc. I'm trying to get the stuff to just work first and
I'll go back and try and improve later!!
BTW I would consider anything I've been able to do so far trivial!! :)
Thanks David!
------------------------------
Date: Thu, 29 Jan 2004 20:41:22 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947F9FB7A206kburdishoptonlinenet@167.206.3.2>
ctcgag@hotmail.com wrote in news:20040129135950.858$M8@newsreader.com:
> Big Swifty <bigswifty00000@yahoo.com> wrote:
>
>> >
>> > foreach (@documents) {
>> > ($doc_id,$doc_name,$score) = $documents[$counter+0],
>> > $documents [$counter+1], $documents[$counter+2];
>> > print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
>> > # PREVIOUS LINE WORKS
>> > print $q->checkbox (-name =>$doc_name,-value => "YES", -label
>> > =>
>> > $doc_name);
>> > # NOT LINE ABOVE
>> > $counter ++;
>> > }
>
> Ok, I think I see now. You think the print works because $doc_id
> contains all three values that you want, and the other two are empty
> (or contain data for the next things, I'm not sure which). If you
> used strict and warnings, Perl would probably explain this to you.
I thought the first print works because I would get 4 rows of discrete
column info, $doc_id, $doc_name, $score
but for each checkbox couldn't see label, and view source showed empty
string for the name.
>
> Nope, the problem occurs before that.
Ok, I recognize it started in childhood!!! :)
>
>> I see a checkbox but no label. If I look at the source the checkbox
>> name is "". I tried quoting $doc_name, unquoting etc etc.
>>
>> yet in the line
>>
>> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
>>
>> the value for the variable prints correctly.
>
> Not really. Change that line to:
>
> print
> "<PRE><TT><B>|||||$doc_id|||||||$doc_name||||$score||||</B></TT></PRE>"
> ;
>
> And see what get's printed.
|||||3|||||||learn_oracle3.txt||||87||||
|||||4|||||||learn_oracle4.txt||||3||||
|||||2|||||||learn_oracle2.txt||||3||||
|||||1|||||||learn_oracle.txt||||3||||
I'm not seeing your point...
>
>> sub select {
>> undef @documents;
>
> don't do that. use strict and my.
OK POINT TAKEN
>
>> $sth = $dbh->prepare("SELECT doc_id,doc_name, SCORE(1) score
>> FROM mydocuments WHERE CONTAINS(document, ?, 1) > 0
>> order by score desc")
>> or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
>> $sth->execute($form_vars{'01_text'}) or die "Can't
>> execute SQL statement: ", $sth->errstr(), "\n";
>>
>> while (@row = $sth->fetchrow_array ) {
>> push (@documents,"$row[0] $row[1] $row[2] ");
>
> What do you think this is doing? Is it adding one thing to
> @documents, or is it adding 3 things to @documents?
>
>> }
>> return @documents;
>> }
>
>
> Xho
>
------------------------------
Date: Thu, 29 Jan 2004 20:53:48 GMT
From: Big Swifty <bigswifty00000@yahoo.com>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947FA1D304AD7kburdishoptonlinenet@167.206.3.2>
Greg:
Please see other posts for the code, and apologies for vague question.
>
> My first question is why you are iterating thru @documents, keeping a
> counter, and then using $counter, $counter+1 andn $counter+2 to refer
> to elements of the array? It would seem like if you had an array of
> the numbers 1-10 printed out what you are doing you would get:
> 1 2 3
> 2 3 4
> 3 4 5
> 4 5 6
> etc.
foreach (@documents) {
> > ($doc_id,$doc_name,$score) = $documents[$counter+0], $documents
> > [$counter+1], $documents[$counter+2];
I was getting the results I wanted with this line
print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
I was trying to get @documents to act like a multi-dimensional array
3 columns and n rows are retrieved from the database, and it looked like it
was working, is it really that weird????
>
> I can't imaging that is what you are trying to do. I'll go out on a
> limb here and say you probably need to be looping through a record set
> rather than an array. If you post more details I imagine someone here
> can help you. I'll certainly try although I am not too familiar with
> the Perl HTML objects.
Yea that sounds like what I was trying to do (record set)
>
> -Greg
>
------------------------------
Date: Thu, 29 Jan 2004 22:07:52 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Can someone tell me what is wrong with this?
Message-Id: <Xns947FAE44C390Adkwwashere@216.168.3.30>
Big Swifty <bigswifty00000@yahoo.com> wrote:
> Glenn Jackman <xx087@freenet.carleton.ca> wrote in
> news:slrnc1ilck.r08.xx087@smeagol.ncf.ca:
>
>> You probably want:
>> while (@row = $sth->fetchrow_array) {
>> push @documents, [@row];
>> }
>> ...
>> foreach my $rowref (@documents) {
>> my ($doc_id,$doc_name,$score) = @$rowref;
>> ...
>>
>
> Glenn:
>
> This worked!! I don't understand yet why, What do the brackets do in
> [@row]
Since @row appears to be defined outside the while() loop, push()ing
references to @row would yield results you probably wouldn't expect. That
is, Glenn deliberately avoided doing this:
push @documents, \@row;
> You are pushing the @row array on top of the @documents array. And then
> dereferencing with @$rowref???
Not quite. The square brackets create an anonymous array, which @row then
populates. These anonymous array references are pushed onto (into?)
@documents, because arrays can only contain scalars (such as references),
not other arrays. So Glenn was dereferencing the references to anonymous
arrays when he used @$rowref. (This paragraph should be taken out and
shot)
> I'm still not sure why I was able to get values for all 3 variables in
> this line but couldn't get $doc_name in next
>
>
> print "<PRE><TT><B>$doc_id $doc_name $score</B></TT></PRE>";
> print $q->checkbox (-name =>$doc_name,-value => "YES", -label =>>
> $doc_name);
Is that your actual code? There's a space after checkbox and an extra >,
so it won't even compile.
--
David Wall
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6030
***************************************