Home: Perl Programming Help: Advanced:
Create a dynamic Object



annabel
New User

May 17, 2010, 10:23 PM


Views: 5588
Create a dynamic Object

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");

What's the difference between the two ways of using a dynamic object is beyond me.
I'm on a deadline with this. Help....


rovf
Veteran

May 18, 2010, 2:07 AM


Views: 5578
Re: [annabel] Create a dynamic Object

Probably different strictness?

I bet you don't get only "Compilation failed", but also a more meaningful error message - do you?

Also, please post a minimal version of the program which still shows the error.

Ronald


annabel
New User

May 18, 2010, 12:37 PM


Views: 5567
Re: [rovf] Create a dynamic Object

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.
Attachments: pipeline.tar (60.0 KB)


rovf
Veteran

May 19, 2010, 3:33 AM


Views: 5537
Re: [annabel] Create a dynamic Object

Sorry if we have a misunderstanding here, but when I wrote in my last response


Quote
please post a minimal version of the program


I did not mean a 60KB tar file. Is it really true that you can't reduce your program further to exhibit this error?

Ronald


FishMonger
Veteran / Moderator

May 19, 2010, 4:56 AM


Views: 5535
Re: [rovf] Create a dynamic Object

rovf,

FYI, this is a cross posted question.

http://bytes.com/topic/perl/answers/888357-create-dynamic-object