By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,177 Members | 976 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,177 IT Pros & Developers. It's quick & easy.

How to create a dynamic Object

P: 2
I'm trying to create an object dynamically using a string as the object type. It works for me with a simple example:

my $string = "Employee";

my $objct = new {$string}("First", "Last", 12345);

Employee is a derived class of a Person class. However, with my real code I get an error: Compilation failed in require at studyMngr.pm line 7. The line triggering it is:

my $nextStepbjct = new {$nextProcessStep}("name");

Line 7 in this file (studyMngr.pm) has use SomeFile.pm.

What's the difference between the two ways of using a dynamic object is beyond me.
I'm on a deadline with this code. Help....
May 18 '10 #1
Share this Question
Share on Google+
3 Replies


Expert Mod 100+
P: 589
Sorry, but your deadline is not our concern. However, if you post a short but complete script that demonstrates the problem, we'll see if we can help.
May 18 '10 #2

P: 2
The full error message is given below.

The code is attached as a tar file. If you run:

perl ChIPSeqPipeline_main.pl it should generate the following error message:

Uncaught exception from user code:
Uncaught exception from user code:
Uncaught exception from user code:
Uncaught exception from user code:
syntax error at ChIPSeqPipeline_processStepMngr.pm line 134, near "}("
Compilation failed in require at ChIPSeqPipeline_studyMngr.pm line 7.
StudyMngr::BEGIN() called at ChIPSeqPipeline_processStepMngr.pm line 7
eval {...} called at ChIPSeqPipeline_processStepMngr.pm line 7
require ChIPSeqPipeline_studyMngr.pm called at ChIPSeqPipeline_main.pl l
ine 7
main::BEGIN() called at ChIPSeqPipeline_processStepMngr.pm line 7
eval {...} called at ChIPSeqPipeline_processStepMngr.pm line 7
BEGIN failed--compilation aborted at ChIPSeqPipeline_studyMngr.pm line 7.
require ChIPSeqPipeline_studyMngr.pm called at ChIPSeqPipeline_main.pl l
ine 7
main::BEGIN() called at ChIPSeqPipeline_studyMngr.pm line 7
eval {...} called at ChIPSeqPipeline_studyMngr.pm line 7
Compilation failed in require at ChIPSeqPipeline_main.pl line 7.
main::BEGIN() called at ChIPSeqPipeline_studyMngr.pm line 7
eval {...} called at ChIPSeqPipeline_studyMngr.pm line 7
BEGIN failed--compilation aborted at ChIPSeqPipeline_main.pl line 7.
Attached Files
File Type: zip pipeline.zip (10.5 KB, 46 views)
May 18 '10 #3

Expert Mod 100+
P: 589
I have no interest in installing and troubleshooting your entire app.

Start by enabling strict in all scripts and fix the problems that are pointed out. Commenting out the use strict lines to get around coding errors is the wrong approach.

Don't use the indirect object syntax.

Change:
Expand|Select|Wrap|Line Numbers
  1. my $objct = new {$string}("First", "Last", 12345); 
To:
Expand|Select|Wrap|Line Numbers
  1. my $objct = ${string}->new("First", "Last", 12345); 
May 19 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.