Eric Walker wrote:

> I have a small grasp of the concept,

What concept?  We don't know what you are responding to.

> but what I am doing involves a
> better understanding than I have.  I am doing a project that will allow
> a user to build a particular file called a do file.  Its used in a route
> tool called iccraftsman.  In this particular file it has several
> sections.  Each section has a few things that are alike.  It seems that
> when I am done this is going to be a pretty big program as we have lots
> of ideas about functionality.  So I figured I would try to do it in OOP
> style for ease of future changes and maintainance.  Hope this helps..

perldoc perlobj

See where that leads you.  It is the basic documentation of OO Perl.  To make
good use of it, you will also have to understand references.  In brief:

Greetings! E:\d_drive\perlStuff>sample_test.pl
Title: Sample of Object Formation in Perl
Purpose: To demonstrate creation of a very simple Perl class, and creation of
ap
propriate methods

Here is the text of Sample.pm

use strict;
use warnings;

package Sample;

sub new {
            my $this = shift;
            my $class = ref($this) || $this;
            my $self = {};
            bless $self, $class;
            $self->initialize(@_);  # parameter my addition to sample
            return $self;
}
#  from perldoc perlref [perlref.pod]
# That is really standard.  You can pretty much plug that in for any class,
then
 start to differentiate
# your class in the initialize function.

sub initialize {
    my $self = shift;   # references the oblect.
    my ($title, $purpose, $text) = @_;

    $self->{'Title'} = $title;
    $self->{'Purpose'} = $purpose;
    push @{$self->{'Text'}}, $_  foreach @$text;
    return $self;
}

sub print {
  my $self = shift;

  print "Title: ";
  print "$self->{'Title'}" if $self->{'Title'};
  print "\nPurpose: ";
  print "$self->{'Purpose'}" if $self->{'Purpose'};
  print "\n\n";
  if ($self->{'Text'}) {
    chomp @{$self->{'Text'}};
    print "$_\n" foreach @{$self->{'Text'}};
  }
}

1;
__END__

Here is the executing code

#!perl -w

use strict;
use warnings;

use Sample;

my $sample_text = [];

push @{$sample_text}, 'Here is the text of Sample.pm', '';
open IN, 'Sample.pm' or die "Can't open module file $!";
push @{$sample_text}, $_  while <IN>;
push @{$sample_text}, '';
push @{$sample_text}, 'Here is the executing code', '';
close IN;
open IN, $0;
push  @{$sample_text}, $_  while <IN>;
close IN;

my $sample = Sample->new('Sample of Object Formation in Perl',
 'To demonstrate creation of a very simple Perl class, ' .
 'and creation of appropriate methods',
 $sample_text);
$sample->print();

Greetings! E:\d_drive\perlStuff>

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to