On 06/20/2007 05:40 AM, Mathew Snyder wrote:
It looks like an object is what I want. Am I correct?

As always, it depends.

Suppose I need to work
with a bit of data that actually has 11 attributes.  This would be an object of
another type.  However, I need to manipulate pieces of it differently.  So I'm
guessing I would create an object thusly:

sub objectname {
    my %hashOfAttribs {
        attrib1 => undef,
        attrib2 => undef,
        attrib3 => undef
    }
}


No.

I would then create an instance of that object

my $instance = new objectname();

I'm not certain though, how to populate the elements.  would it actually be
my $instance = new objectname(attrib1 => value, attrib2 => value, attrib3 =>
value)?  Or would I create the instance as above and then populate it by some
other means?  For instance
$instance->hashOfAttribs {
    attrib1 => value,
    attrib2 => value,
    attrib3 => value
};

Am I at least on the right track?


Not really. First, it hasn't been conclusively established that you need objects. You haven't described the data and what you want to do with it.

Second, objects are created using the methods described in "perldoc perlboot," "perldoc perltoot" and "perldoc perltooc."

However, you can simplify things considerably by using Class::Struct, e.g.:

use Class::Struct ObjectName => [
    attrib1 => '$',
    attrib2 => '$',
    attrib3 => '$',
    children => '$',
    ];

 ...

my $instance = ObjectName->new(
    attrib1 => '10',
    attrib2 => [1, 20, 1943],
    attrib3 => 'Hello',
    children => []);




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to