>>>>> "Rod" == Rod Za <[EMAIL PROTECTED]> writes:

Rod> Hi, i like to create somethings like classes in an OOP language.
Rod> The code below is correct?

Rod> _BEGIN_
Rod> package PACKAGE_NAME;
Rod> use strict;
Rod> use warnings;
Rod> our $VERSION = '0.1';
Rod> sub new{

my $class = shift;

Rod>         my $self = {};
Rod>          $self->{SOME_VAR} = undef; 
Rod>          $self->{SOME_VAR2} = undef;
Rod>         bless $self;

No, bless $self, $class;

Rod>         return $self;
Rod> }

Rod> sub init{
Rod>         my $self = shift;
Rod>         $self->{SOME_VAR} = shift;
Rod>         $self->{SOME_VAR2} = shift;
Rod>         return $self;
Rod> }

Rod> sub SOME_SUB{
Rod>        my $self = shift;
Rod>        my $sum = ($self->{SOME_VAR} * $self->{SOME_VAR2});
Rod>        return $sum;
Rod> }
Rod> 1;
Rod> _END_

Rod> what the 'bless' do?

Associates the data structure with a  particular package, so that methods
can be found.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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


Reply via email to