meetn2veg has asked for the wisdom of the Perl Monks concerning the following question:
One table in my db only contains 'widgets' for left-hand and right-hand colums for my pages, called up according to a page_id, the selected language of the visitor, etc...
If there's a subroutine name within the 'sub' db field, I want to call that sub from a previously required library.cgi file, else if there's no subroutine specified within the 'sub' db field, print the data that's in the 'title' and 'text' fields.
Here's the code:
##### Get LHC widgets based on $pid my $dbh = Mysql->connect($DBHOST2, $DBDATA2, $DBUSER2, $DBPASS2); my $qry = qq¿SELECT title,text,sub FROM widgets WHERE page_id = '$ +pid' AND user_lang = '$USER_LANG' AND type = 'lefthandcol' ¿; my $result = $dbh->query($qry); while (my @db = $result->fetchrow){ $LHC_OPTIONS .= ($db[2] ne "") ? &{$db[2]}() : qq¿$db[0]:$db[1 +]<BR>¿ ; }
The data in the 'sub' field is just the name of the routine - ie: build_table - no leading ampersand or trailing brackets.
Even though I'm using strict, I've already soft-referenced things without producing an error (I build my menus from flat-file db's and I use the same &{$array[0]}() structure). However, this code just produces a "Premature end of script headers" error.
Can anyone tell me how I can call a subroutine using the value contained within a database?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/MySQL - calling sub from name in dbase
by blue_cowdawg (Monsignor) on Oct 18, 2005 at 13:37 UTC | |
|
Re: Perl/MySQL - calling sub from name in dbase
by osunderdog (Deacon) on Oct 18, 2005 at 13:39 UTC | |
|
Re: Perl/MySQL - calling sub from name in dbase
by graff (Chancellor) on Oct 19, 2005 at 02:26 UTC |