1

I'm not sure if the title is exactly right. What I'm trying to do is this (I've already gotten the database handle from DBI):

my $idcenter = 4;
my $getCenter = $dbh->prepare(
<<SQLEND
select * from center
where uidcenter = ?
SQLEND
);

my @tables = ("Center");
foreach $table (@tables) {
    my $func = "get$table";
    $func->bind_param(1, $idcenter);
    etc.
}

So, how do I construct a variable that points (? is that right?) to a function? Is there a way?

1 Answer 1

3

You use a hash

my %get_table = (
    center => $getCenter,
);

$get_table{"center"}->bind_param(1, $idcenter);
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, thank you! I was using a hash table before, but I didn't put the dollar sign in front of getCenter.
Make sure you have use strict; and use warnings; at the top of each and every perl script. If you did and you forgot that dollar sign, perl would give you the following helpful error: Bareword "getCenter" not allowed while "strict subs" in use

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.