help with perl database printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with perl database printing
# 1  
Old 11-19-2011
help with perl database printing

Hey guys i am using perl and trying to pull a list of books from a database and then populate the list in a separate TT2 file. When the list is generated there should be 39 book names. When I do the foreach statement in my tt2 below, the first statement gives me 39 Array(random number) and the second way gives me 39 Hash(random number). How do i get it to display the name in the database?

Perl file:

Code:
#!/usr/bin/perl-w

##############################################
use strict;
use Template;
use DBI;
use CGI;
use warnings;


my $user='web';
my $password='nouser';
my $db='bible';
my $dsn = "DBI:mysql:$db";
my $dbh = DBI->connect($dsn, $user, $password) or die $DBI::errstr;

$tt_object = Template->new(
   {
   INCLUDE_PATH =>
               [ '/export/srv/www/vhosts/main/tt2' ]
   }
   );
$template = '1.tt2';

my($template, $tt_object, $cgi_object, $sample, $vars, $title,$heading,
   %where);

my $N_query=qq~SELECT distinct(bname) FROM kjv WHERE bsect='N'~;

my $sth=$dbh->prepare($N_query);
$sth->execute;
my $N_booknames=$sth->fetchall_arrayref({});


$vars = {
               N_booknames =>$N_booknames,
       };

$tt_object->process ( $template, $vars ) || die;


__END__

TT2 file:

Code:
[% FOREACH i IN N_booknames %]
<option value="[% i %]">[% N_booknames.$i %]</option>
[% END %]

[% FOREACH i IN N_booknames %]
<option value="[% i %]">[% N_booknames %]</option>
[% END %]

# 2  
Old 11-20-2011
Not sure. Try this:
Code:
  N_booknames =>@$N_booknames,

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Help with mySQL database by perl script

Hello; I was trying to set up a mysql database using following script, but never went through. The code seems fine without any syntax error as I tested it: perl -c Brapa0101-db.pl Brapa0101-db.pl syntax OKHowever, whenever I run it, an error message was tossed out: DBD::mysql::st execute... (7 Replies)
Discussion started by: yifangt
7 Replies

2. Shell Programming and Scripting

[Perl] script -database

Welcome. I am writing a perl script. I have to design a database consisting of a single table (any subject) saved in a text file. (I make it vi command name and I am giving permission chmod u + x?) The table should contain at least four columns, including a column containing the ID (serial number )... (4 Replies)
Discussion started by: qwerty007
4 Replies

3. Shell Programming and Scripting

How to use awk for printing line from database table?

Hi , I have inserted some records in a table having column "value1 varchar2(4000)" and want to spool in a file. I have written as below set echo off set feed off set hea off set wra off set lin 500 spo temp_table and fired select query as below select value1 from temp_table; spo... (6 Replies)
Discussion started by: CaapAjayShukla
6 Replies

4. Shell Programming and Scripting

perl, testing a database for a match

hi there. in perl, I am struggling to find a simple method of connecting to a database, determining if the result of my query is "true" and then testing against the result. I dont even really want the data that i am 'SELECT'íng. i effectively just want to check that a record exists with a UID... (2 Replies)
Discussion started by: rethink
2 Replies

5. Shell Programming and Scripting

Printing between 2 matches with Perl

Can we please modify this perl one-liner to print lines between pattern1 and pattern2 in a file? Currently it prints lines till pattern2. (4 Replies)
Discussion started by: anand_bh
4 Replies

6. Shell Programming and Scripting

Automating A Perl Script over a database

Dear Scripting Gods I've never done shell scripting before and have only recently got to grips with Perl, so apologies for my naivity. I've written a perl program which takes in two files as arguments (these are text documents which take in the information I need) The perl program spits out a... (1 Reply)
Discussion started by: fraizerangus
1 Replies

7. Shell Programming and Scripting

[Perl] Printing - Scalars

Hey Guys, I have some weird problem with printing scalars ... When I'm executing script both are printing in terminal ... But only one is printed to the file ? I don't know whats going on .. :) Btw .. I'm noobie :) took me lots of time to put this simple script together :) Thank you... (3 Replies)
Discussion started by: NDxiak
3 Replies

8. Shell Programming and Scripting

perl hash of hashes from database

hi there, I have some database output that looks like this SELECT nic_name,nic_duplex,nic_speed,nic_ip FROM network_table WHERE hostname = "server1" result is this (ive delimited with a pipe for ease of reading) bge0|full|1000|10.32.100.1 bge1|full|1000|11.12.101.7 ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

9. Shell Programming and Scripting

Perl printing error

Hi Scripting Gurus, I am new bee in perl, and trying to write a script which must print the free disk space availability of C and E drives. Please advice. Here is the script snippet and expected output: #!/usr/bin/perl use CGI qw/:html3 :standard/; $spaceuselog =... (4 Replies)
Discussion started by: ccsaviour
4 Replies

10. Shell Programming and Scripting

Perl Database access

Hi, I tried to run this code but it isnt giving me any output or errors. My aim is to retrieve the row based on the flag name(this is the primary key). flag_test is my table This is how i ran it: perl read_db.pl flag1 flag1 is the criteria in where clause -------- this is my... (2 Replies)
Discussion started by: mercuryshipzz
2 Replies
Login or Register to Ask a Question