473,403 Members | 2,293 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,403 software developers and data experts.

Complex Objects in Perl

Can someone point me to an example of how to implement and access the kind
of object shown below?

Most of the examples if found are an object that contains one other object.
I need to create an object that contains a hash of sub-objects each
sub-object is made up of a number of different objects and an array of an
object type.

Object1 contains scalars

Object2 Contains scalars

Object3 contains scalars (OK that part is easy)

Object4 contains an Object1, an Object2, an array of Object3, and scalars

Object5 contains a hash of Object4 and scalars

Object6 contains a hash of Object5

In general I will get or set each element in each object individually.

The ability to enumerate the object3s in the Object6 and the ability to

Enumerate through the object4s an object5 are the only other complex
accesses I need.

Thanks,

-Pat
Jul 19 '05 #1
5 5748
In article <8_********************@adelphia.com>, John Smith
<so*****@microsoft.com> wrote:
Can someone point me to an example of how to implement and access the kind
of object shown below?

Most of the examples if found are an object that contains one other object.
I need to create an object that contains a hash of sub-objects each
sub-object is made up of a number of different objects and an array of an
object type.

Object1 contains scalars

Object2 Contains scalars

Object3 contains scalars (OK that part is easy)

Object4 contains an Object1, an Object2, an array of Object3, and scalars

Object5 contains a hash of Object4 and scalars

Object6 contains a hash of Object5

In general I will get or set each element in each object individually.

The ability to enumerate the object3s in the Object6 and the ability to

Enumerate through the object4s an object5 are the only other complex
accesses I need.


Objects in Perl are implemented as a reference to an anonymous hash.
The keys to the hash are the names of the members, and the values of
the hash may be any scalar. This includes normal scalar values and
references. Thus, a member of your object may be a reference to an
array or a hash or it may be another object (reference to a hash) or a
method (reference to subroutine). So you can have any level of nesting
of objects-within-objects and arrays or hashes of other objects. You
enumerate over array and hash members as you would enumerate over any
array or hash given a reference to one of these.

See the following documentation built into your installation of perl:

'perldoc perlreftut' Perl references tutorial
'perldoc perldsc' Perl data structures cookbook
'perldoc perllol' Manipulating arrays of arrays in Perl
'perldoc perlboot' Beginner's object-oriented tutorial

FYI: this newsgroup is defunct; try comp.lang.perl.misc in the future.
Jul 19 '05 #2
Jim Gibson wrote:
In article <8_********************@adelphia.com>, John
Smith
<so*****@microsoft.com> wrote:

Objects in Perl are implemented as a reference to an
anonymous hash.
The keys to the hash are the names of the members, and the
values of
the hash may be any scalar. This includes normal scalar
values and
references. Thus, a member of your object may be a
reference to an
array or a hash or it may be another object (reference to
a hash) or a
method (reference to subroutine). So you can have any
level of nesting
of objects-within-objects and arrays or hashes of other
objects. You
enumerate over array and hash members as you would
enumerate over any
array or hash given a reference to one of these.

See the following documentation built into your
installation of perl:

'perldoc perlreftut' Perl references tutorial
'perldoc perldsc' Perl data structures cookbook
'perldoc perllol' Manipulating arrays of arrays in
Perl
'perldoc perlboot' Beginner's object-oriented
tutorial


Thanks for the info. I have been using perl on and off but
never tried its OO feature.
I followed the example in perlcod perlboot but got an error.

Here is my code
--------------------

Cow->speak;

{ package Animal;
sub speak {
my $class = shift;
print "a $class goes ",$class->sound,"!\n";
}
}

{ package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
print "Hi >$ISA[0]>\n";
sub sound {"Mooo"}
}
---------------------
After execution, I got

C:\Perl\MDGS>
C:\Perl\MDGS>
C:\Perl\MDGS>Sample.pl
Can't locate object method "speak" via package "Cow" at
C:\Perl\MDGS\Sample.pl line 2.

--------------------

Does this mean perl can't recgnize @ISA?

Thanks,
pac
Jul 19 '05 #3
"packat" <ch*****@verizon.not> schreef in bericht
news:NPY_d.24692$hA3.5491@trnddc09...
Jim Gibson wrote:
In article <8_********************@adelphia.com>, John Smith
<so*****@microsoft.com> wrote:

Objects in Perl are implemented as a reference to an anonymous hash.
The keys to the hash are the names of the members, and the values of
the hash may be any scalar. This includes normal scalar values and
references. Thus, a member of your object may be a reference to an
array or a hash or it may be another object (reference to a hash) or a
method (reference to subroutine). So you can have any level of nesting
of objects-within-objects and arrays or hashes of other objects. You
enumerate over array and hash members as you would enumerate over any
array or hash given a reference to one of these.

See the following documentation built into your installation of perl:

'perldoc perlreftut' Perl references tutorial
'perldoc perldsc' Perl data structures cookbook
'perldoc perllol' Manipulating arrays of arrays in Perl
'perldoc perlboot' Beginner's object-oriented tutorial

Thanks for the info. I have been using perl on and off but never tried
its OO feature.
I followed the example in perlcod perlboot but got an error.

Here is my code
--------------------

Cow->speak;


Which Cow, which speak?

{ package Animal;
sub speak {
my $class = shift;
print "a $class goes ",$class->sound,"!\n";
}
}

{ package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
print "Hi >$ISA[0]>\n";
sub sound {"Mooo"}
}
---------------------
After execution, I got

C:\Perl\MDGS>
C:\Perl\MDGS>
C:\Perl\MDGS>Sample.pl
Can't locate object method "speak" via package "Cow" at
C:\Perl\MDGS\Sample.pl line 2.

--------------------

Does this mean perl can't recgnize @ISA?

Thanks,
pac


Move your speaking cow to the point beyond the package declarations and she
will no longer be silent.

Theo van den Heuvel
Jul 19 '05 #4
Theo van den Heuvel wrote:
"packat" <ch*****@verizon.not> schreef in bericht
news:NPY_d.24692$hA3.5491@trnddc09...
Jim Gibson wrote:
In article <8_********************@adelphia.com>, John
Smith
<so*****@microsoft.com> wrote: Here is my code
--------------------

Cow->speak;


Which Cow, which speak?

{ package Animal;
sub speak {
my $class = shift;
print "a $class goes ",$class->sound,"!\n";
}
}

{ package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
print "Hi >$ISA[0]>\n";
sub sound {"Mooo"}
}
---------------------
After execution, I got

C:\Perl\MDGS>
C:\Perl\MDGS>
C:\Perl\MDGS>Sample.pl
Can't locate object method "speak" via package "Cow" at
C:\Perl\MDGS\Sample.pl line 2.

--------------------

Does this mean perl can't recgnize @ISA?

Thanks,
pac


Move your speaking cow to the point beyond the package
declarations
and she will no longer be silent.


{package packat;
sub sound {"Duh!"}
}

I just follow the sample code in perldoc without reordering
the sequesce....
It works fine now. Hmmm.. I have a great projct for it.

Thnaks for you help,
pac
packar->
Duh!
Theo van den Heuvel

Jul 19 '05 #5
>>>>> "packat" == packat <ch*****@verizon.not> writes:

packat> Cow-> speak;
packat> { package Animal;
packat> sub speak {
packat> my $class = shift;
packat> print "a $class goes ", $class->sound, "!\n";
packat> }
packat> }
packat> { package Cow;
packat> use vars qw(@ISA);
packat> @ISA = qw(Animal);
packat> print "Hi >$ISA[0]>\n";
packat> sub sound {"Mooo"}
packat> }

packat> After execution, I got
packat> Sample.pl Can't locate object method "speak" via package
packat> "Cow" at C:\Perl\MDGS\Sample.pl line 2.

packat> Does this mean perl can't recgnize @ISA?

It means you've put the "Cow->speak" too early, before Perl execute
the statements that assigns @Cow::ISA. Try putting it into the last
statement, and remember that Perl execute each file in your program
line by line (except that subroutines are defined before anything is
executed, together with the things you put in BEGIN {}, includes by
"use", etc).

Regards,
Isaac.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
2
by: Lionel | last post by:
Hi all, I would like having more informations on how we could exchange informations and/or objects between PERL and JAVA. We have a Java programs that open, maintain and close telnet...
4
by: spar | last post by:
I'm converting a Perl script to Python and have run into something I'm not sure how to do in Python. In Perl, I am running through a couple loops and inserting values directly into a complex...
2
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a...
0
by: Vic Russell | last post by:
Hi, I have a soap server running on Linux using SOAP::Lite and it communicates with a simple perl client on an XP machine and returns a complex perl object OK. I now want to do the same with a...
11
by: Sven Neuberg | last post by:
Hi, I have been handed the task of updating and maintaining a web application, written in ASP and Javascript, that takes complex user inputs in HTML form and submits them to server-side ASP...
5
by: Trail Monster | last post by:
Ok, I've been searching the net now for several days and can't find how to do this anywhere. Version: VS 2005 Professional Release, 2.0 Framework Background: I have a complex business object...
2
by: =?Utf-8?B?ZHNoZW1lc2g=?= | last post by:
Hello, My problem is a little complex... Here it goes: I have a web service in my system which my users need to web reference. By web referencing my web service, my users can use all kinds of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.