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.
In reply to calling a method within a constructor by ocs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |