Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

references
i know this should be a simple step or two that i'm missing, and i
haven't been able to figure it out from reading yet...

i have the following code:

$sth = $mysql_dbh->prepare("select subroutine_pointer from
$database.equipment_manufacturer where
manufacturer=\"$remedy_eqpt_mfgr\"");
$sth->execute();
$subroutine_pointer = $sth->fetchrow_array();
no strict "refs";
&$subroutine_pointer() unless $subroutine_pointer eq "";
use strict "refs";

this pulls a phrase from the database that matches a subroutine name
that i want to call based on certain other criteria, then displays that
sub's output to a web page.  this works fine as is but i want to learn
how to restructure this so i don't have to use "no strict" and "use
strict" around the call.  all suggestions welcome *s*

joe


Report this thread to moderator Post Follow-up to this message
Old Post
Joe Mecklin
03-27-04 04:14 AM


Re: references

> i know this should be a simple step or two that i'm missing, and i
> haven't been able to figure it out from reading yet...
>
> i have the following code:
>
> 	$sth = $mysql_dbh->prepare("select subroutine_pointer from
> $database.equipment_manufacturer where
> manufacturer=\"$remedy_eqpt_mfgr\"");
> 	$sth->execute();
> 	$subroutine_pointer = $sth->fetchrow_array();
> 	no strict "refs";
> 	&$subroutine_pointer() unless $subroutine_pointer eq "";
> 	use strict "refs";
>
> this pulls a phrase from the database that matches a subroutine name
> that i want to call based on certain other criteria, then displays that
> sub's output to a web page.  this works fine as is but i want to learn
> how to restructure this so i don't have to use "no strict" and "use
> strict" around the call.  all suggestions welcome *s*
>

One way, I won't guarantee the best, would be to store a mapping of
subroutine references into a hash, where the hash key replaces the
subroutine name, then you would index into the hash using the value from
the db to access the reference of the sub to call.

%subs = ( 'db_value1' => sub { print "Called sub 1"; },
'db_value2' => sub { print "Called sub 2"; }, );

$subs{$subroutine_pointer}->();

Where $subroutine_pointer is the string 'db_value1', etc.

http://danconia.org

Report this thread to moderator Post Follow-up to this message
Old Post
Wiggins D Anconia
03-27-04 04:14 AM


Re: references
On Wed, 2004-03-24 at 15:08, Wiggins d Anconia wrote: 
>
> One way, I won't guarantee the best, would be to store a mapping of
> subroutine references into a hash, where the hash key replaces the
> subroutine name, then you would index into the hash using the value from
> the db to access the reference of the sub to call.
>
> %subs = ( 'db_value1' => sub { print "Called sub 1"; },
>           'db_value2' => sub { print "Called sub 2"; }, );
>
> $subs{$subroutine_pointer}->();
>
> Where $subroutine_pointer is the string 'db_value1', etc.
>
> http://danconia.org

thanks for the ideas.  i played with them some but couldn't get anything
to work.  right now time is an issue so i'll just leave things as they
are but will come back to these ideas when i have more time.  i
appreciate the quick responses.  thanks again.

joe



Report this thread to moderator Post Follow-up to this message
Old Post
Joe Mecklin
03-27-04 04:14 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:42 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.