snra_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi ,

I need to create a class containg the datatypes string,
arrays of objects of other classes and hashes . How do i define all these things in the constructor.

When i create a object i will pass the string datatypes and the array and
hashes would be empty and later on will update the arrays and hashes using the setter fucntions.

Please help me out in creating a constructor which blesses all of the above datatypes.

Most of the tutorials talks about blessing a simple scalar and accessing the same using a function.

Since i have come from Java background my mind is still under pressure to think in perlish way.

Your help would be greatly helpful so that i can keep adding the functionalities over the hint you guys provide.

Thanks !!!!

Replies are listed 'Best First'.
Re: Create a class with mutiple datatypes
by mzedeler (Pilgrim) on Jul 29, 2009 at 20:01 UTC

    Welcome to the perl community!

    Try looking in perltoot, then write your own package (class) and come back when you have some code done.

Re: Create a class with mutiple datatypes
by Bloodnok (Vicar) on Jul 30, 2009 at 14:19 UTC
    I would suggest that, rather than have a single class defining all of the other data types, you declare a single class of your own, utilising the Composite pattern.

    CPAN contains numerous existing class implementations - some of which may be suitable for your purpose - for inclusion in the composing class. However, if there's nothing suitable, roll your own class (see perlmodlib & perlmod) for each data type in which you're interested and include that in your composing class.

    A user level that continues to overstate my experience :-))