473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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
3 3214
RonB
589 Expert Mod 512MB
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
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, 64 views)
May 18 '10 #3
RonB
589 Expert Mod 512MB
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

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

Similar topics

2
by: Simon | last post by:
Am using the following code. <script language="JavaScript1.2"> function setquantity(productindex,productquantity) { //create the reference object irefname_none = eval("document." +...
7
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET)...
22
by: Peter Ammon | last post by:
A friend was asked "How many ways are there to create an object in C++?" in an interview. Apparently, the "right" answer was eleven. Does anyone know how the interviewer arrived at that number? ...
2
by: Nak | last post by:
Hi there, I'm using Activator.CreateInstance to create an object from a string, unfortunately it requires that I have a constructor with no parameters (at least I presume) I was wondering if...
1
by: androidsun | last post by:
Hi, Does anyone know how to do it? I have an oCommandWrapper that has an input paramater{{"@registrationId",DbType.String,strRegCode}} and two output paramerters...
5
by: Sergio Montero | last post by:
I have a MustInherits Base class that implements a custom IDataLayer interfase. IDataLayer expose CRUD methods. Base class constructor requires two parameters: ConnectionString TableName ...
5
by: plsHelpMe | last post by:
How to create dynamic javascript arrays using dojo toolkits Hello frens, I am in a big trouble. My objective is: I am having some categories shown by differnent radio buttons, on the click of...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
4
by: Michael Munch | last post by:
Hi I want to read the value of af text-field, create dynamic, in a form. Se below a small test-site to do that (but readning fails): I use the function Test_Read for reading the value from the...
4
by: Sunny | last post by:
Hi, Is there a way in javascript to create Dynamic arrays or arrays on fly. Something Like: var "ptsgN"+sd = new Array(); Here sd is incrementing by 1. I have lots of data that I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.