Hi,
I am trying to create an object for a perl class but am getting stumped. I was wondering if anyone could help me with this. Here is my class definition:
=======================================
package log;
use strict;
#constructor
sub new {
my ($class) = @_;
my $self = {
_filename => undef,
_descriptor => undef
};
bless $self, $class;
return $self;
}
#accessor method for Log filename
sub FileName {
my ($self, $filename)=@_;
$self->{_filename} = $filename if defined ($filename);
return $self->{_filename};
}
#accessor method for Log Descriptor
sub Descriptor{
my ($self, $descriptor) = @_;
$self->{_descriptor} = $descriptor if defined ($descriptor);
return $self->{_descriptor};
}
sub readParse{
my ($self) = @_;
}
sub print{
my ($self) = @_;
#print Log info
printf("Name:%s %s\n\n", $self->filename, $self->descriptor);
}
1;
==============================================
And here's my object creation:
=============================================
#/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use log;
my $khurt = eval { new log(); } or die ($@);
=================================================
And here's the error I am getting:
=================================================
syntax error at logclass.pl line 9, near "new log"
Execution of logclass.pl aborted due to compilation errors (#1)
(F) Probably means you had a syntax error. Common reasons include:
A keyword is misspelled.
A semicolon is missing.
A comma is missing.
An opening or closing parenthesis is missing.
An opening or closing brace is missing.
A closing quote is missing.
======================================================
Sorry for entering questions back to back but I want to have a good working knowledge of perl.
Thanks
ro
I am trying to create an object for a perl class but am getting stumped. I was wondering if anyone could help me with this. Here is my class definition:
=======================================
package log;
use strict;
#constructor
sub new {
my ($class) = @_;
my $self = {
_filename => undef,
_descriptor => undef
};
bless $self, $class;
return $self;
}
#accessor method for Log filename
sub FileName {
my ($self, $filename)=@_;
$self->{_filename} = $filename if defined ($filename);
return $self->{_filename};
}
#accessor method for Log Descriptor
sub Descriptor{
my ($self, $descriptor) = @_;
$self->{_descriptor} = $descriptor if defined ($descriptor);
return $self->{_descriptor};
}
sub readParse{
my ($self) = @_;
}
sub print{
my ($self) = @_;
#print Log info
printf("Name:%s %s\n\n", $self->filename, $self->descriptor);
}
1;
==============================================
And here's my object creation:
=============================================
#/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use log;
my $khurt = eval { new log(); } or die ($@);
=================================================
And here's the error I am getting:
=================================================
syntax error at logclass.pl line 9, near "new log"
Execution of logclass.pl aborted due to compilation errors (#1)
(F) Probably means you had a syntax error. Common reasons include:
A keyword is misspelled.
A semicolon is missing.
A comma is missing.
An opening or closing parenthesis is missing.
An opening or closing brace is missing.
A closing quote is missing.
======================================================
Sorry for entering questions back to back but I want to have a good working knowledge of perl.
Thanks
ro