in reply to mod_perl advice required

Well as you can probably guess I'm a mod_perl/perl newbie, trying to feel my way along learning as I go. What you say makes perfect sense, but heres some of my search code anyway.

#!/usr/bin/perl -W use CGI qw(param); use CGI::Carp qw(fatalsToBrowser); use DBIx::FullTextSearch; use DBIx::FullTextSearch::StopList; use DBI; use HTML::Template; use HTML::Template::Expr; my $dbh = DBI->connect('dbi:mysql:search','??????','??????') or die("C +ould not connect to database"); my $cbh = DBI->connect('dbi:mysql:cobra3','??????','??????') or die("C +ould not connect to database"); my $search = param("search_string"); my $fts = DBIx::FullTextSearch->open($dbh, '??????'); my @files = $fts->search($search); if (@files) { foreach $filename(@files){ $filename = substr($filename,0,-4); my $sth = $cbh->prepare("SELECT id, title, summary FROM resourc +e WHERE id =?"); $sth->execute($filename); while (my $ref = $sth->fetchrow_hashref()){ my $title = $ref->{title}; my $id = $ref->{id}; push @rows, { ID => $id, TITLE => $title }; } } } my $template = HTML::Template->new(filename => 'ee_search.tmpl'); $template->param(SEARCH_STRING => $search); $template->param(ROWS => \@rows); print "Content-type: text/html\n\n"; print $template->output;
I know this is a big hint for me but I use 'strict' I get an error, I'm not sure how to assign the $filename and @rows to an explicit package name???

Replies are listed 'Best First'.
Re: Re: mod_perl advice required
by DrManhattan (Chaplain) on Feb 25, 2003 at 15:39 UTC

    strict is your friend. :) It's telling you that you need to explicitly scope $filename and @rows. Try this:

    my @rows;
    if (@files) {
        foreach my $filename(@files){
    $filename = substr($filename,0,-4); my $sth = $cbh->prepare("SELECT id, title, summary FROM resourc +e WHERE id =?"); $sth->execute($filename); while (my $ref = $sth->fetchrow_hashref()){ my $title = $ref->{title}; my $id = $ref->{id}; push @rows, { ID => $id, TITLE => $title }; } } } my $template = HTML::Template->new(filename => 'ee_search.tmpl'); $template->param(SEARCH_STRING => $search); $template->param(ROWS => \@rows);

    -Matt

      In a way, use strict is more important than warnings.
Re: Re: mod_perl advice required
by OM_Zen (Scribe) on Feb 25, 2003 at 16:08 UTC
    Hi ,

    The use strict pragma is important as your program runs through mod-perl as mod-perl behaves negatively if you have variables that are global without scope and as you know use strict will surely not entertain global variables

      Not quite correct. It will not entertain undeclared global variables. (Or undeclared lexical variables, for that matter, but AFAIK a variable has to be declared to be lexically scoped anyway.)