ocs has asked for the wisdom of the Perl Monks concerning the following question:
Hey monks,
this is an apparently easy to answer question, but I have not found an answer with a quick search over perlmonks.
All I want to do is to call a method of a class within the constructor of the class. But at this point it isn't blessed yet. So how do I handle this best without calling the method explicit after creating the object?
Any clues welcome! Thanks in advance.
package Disk; use strict; # constructor sub new { my $class = shift; my $device = shift; my $self = { 'device' => $device, 'info' => setInformation($device), # this is the method i want to +be called }; bless $self, $class; } sub setInformation { my $self = shift; my $device = shift; my $model = qx(hdparm -i $device | grep -i model); $self->{'info'} = $model =~ /.*model=(.+?),.*/i; } sub getInformation { my $self = shift; return $self->{'info'}; }
tennis players have fuzzy balls.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calling a method within a constructor
by dirving (Friar) on Apr 11, 2007 at 08:29 UTC | |
by ocs (Monk) on Apr 11, 2007 at 08:44 UTC | |
by dragonchild (Archbishop) on Apr 11, 2007 at 11:34 UTC | |
|
Re: calling a method within a constructor
by tirwhan (Abbot) on Apr 11, 2007 at 08:42 UTC | |
by ocs (Monk) on Apr 11, 2007 at 08:53 UTC |