0

perl object "plan" has subroutine "plan_exec_time";

my $p = Plan->new;

i can call it by this way : $p->plan_exec_time

but $p->"plan_exec_time" dos not works.

now i want access the subroutine by variable refer:

my $t = "plan_exec_";

$p->"${t}time"

this is also not works

how to access the object's subroutine but donot through create an temp variable ?

because this works :

my $x = "${t}time";
$p->$x;
2
  • Can you show what error message you are getting when calling this function? Commented Jan 28, 2013 at 8:10
  • Check the path of the Plan module. Like this: perl -e Plan.pm Commented Jan 28, 2013 at 8:11

2 Answers 2

3
my $t = "plan_exec";
$p->can($t."_time")->($p)

The can method returns ref to the method.

Sign up to request clarification or add additional context in comments.

1 Comment

some explanation would help the OP
0

I don't understand why you would want to avoid using a temporary variable - any other solution will be ugly and hacky. But you can reference and dereference a string in one go, like this

my $p = Plan->new;
my $t = "plan_exec_";
$p->${\"${t}time"};

Comments

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.