Can someone tell me what is wrong with this?

B

Big Swifty

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 ++;
}
 
C

ctcgag

Big Swifty said:
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
 
C

cp

Big said:
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'
 
B

Big Swifty

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
 
B

Big Swifty

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];



Thanks!!!
 
B

Big Swifty

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 ++;
}
 
G

Glenn Jackman

Big Swifty said:
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;
...
 
G

gnari

Big Swifty said:
Hi Xho:

Can you tell me what you mean by this?


You seem to be incoherently mixing an iterator "for" loop with a index
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
 
G

G Klinedinst

Big Swifty said:
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
 
C

ctcgag

Big Swifty said:
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
 
D

David K. Wall

Glenn Jackman said:
Big Swifty said:
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
 
C

ctcgag

Big Swifty said:
Hi Xho:

Can you tell me what you mean by this?

You seem to be incoherently mixing an iterator "for" loop with a index

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
 
B

Big Swifty

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!!!
 
B

Big Swifty

"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!
 
B

Big Swifty

Big Swifty said:
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!!! :)
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...


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
 
B

Big Swifty

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)
 
D

David K. Wall

Big Swifty said:
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.
 
G

gnari

Big Swifty said:
|||||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...

did you make the program print it or did you just write
what you assumed would be printed?

because see the following snippet:
while (@row = $sth->fetchrow_array ) {
push (@documents,"$row[0] $row[1] $row[2] ");

see you are adding one string only, that happen to contain the 3 values,
so the
print
"<PRE><TT><B>|||||$doc_id|||||||$doc_name||||$score||||</B></TT></PRE>";
above should have printed:
|||||3 learn_oracle3.txt 87 |||||||||||||||

gnari
 
B

Big Swifty

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)
THANKS for the explanation!

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

I think the > got added from copy/paste but it seems that it works with
checkbox and space.
 
T

Thomas Kratz

Glenn said:
Big Swifty said:
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;
...

Or even better because you can access the values by name nad DBI does
everything for you as long as the columns are named:

sub select {

...

my $docs = $sth->fetchall_arrayref({});

return($docs);
}

and later

my $selected = select();

foreach my $doc ( @$selected ) {
... do something with $doc->{doc_id}, $doc->{doc_name} and
$doc->{score}
}

It looks so much clearer, than referring to the result by column number,
although it has to be somewhat slower (never benchmarked this, never mattered)

Thomas
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top