|
Posted by Marc on March 20, 2007, 12:18 pm
Please log in for more thread options
I've made some progress based on your feedback. When I tried:
my ($self, $sheetname) = @_;
it thought $self was the value of what the $sheetname was supposed to
be, throwing the following error:
Use of uninitialized value in concatenation (.) or string at line 161.
Can't locate object method "workbook" via package
"[sheetnameVariable]" (perhaps you forgot to load
"[sheetnameVariable]"?) at line 162.
the print sheetname statement had output:
"sheetname = "
So I flipped them and the print sheetname statement had output:
"sheetname = [sheetnameVariable]"
but I got this error at the same line (161):
"Can't call method "workbook" on an undefined value"
so apparently it still doesn't know what $self is. This method is
being called from another method in the module with like this:
my $Worksheet = CreateWorksheet($title);
sub CreateWorksheet
{
my ($sheetname, $self) = @_;
#if (@_) { my $sheetname = shift; }
#my $self;
#my $sheetname = shift;
print("sheetname = $sheetname");
my $WorkSheet = $self->workbook->add_worksheet($sheetname);
#line 161
#my $WorkSheet = my $workbook->add_worksheet($sheetname);
$WorkSheet->set_landscape();
$WorkSheet->fit_to_pages(1);
$WorkSheet->repeat_rows(0);
$WorkSheet->set_header("&C" . $sheetname);
return my $Worksheet;
}
On Mar 20, 11:12 am, "Mumia W." <paduille.4060.mumia.w
+nos...@earthlink.net> wrote:
> On 03/20/2007 10:03 AM, Marc wrote:
>
>
>
> > I'm working on making an object oriented module in Perl for the first
> > time and have run into an error that I'm having trouble with:
> > "Can't call method "workbook" without a package or object
> > reference..."
>
> > In my CreateWorksheet method, I'm passing a value for the worksheet
> > name. But I also need to be able to reference $self at the same time.
> > How can I do this correctly?
>
> > sub new {
> > my $class = shift;
> > my $self = {};
> > $self-> = undef;
> > $self-> = undef;
> > $self-> = 'Invoice.xls';
> > $self-> = our $workbook;
>
> > bless ($self, $class);
> > return $self;
> > }
>
> > sub CreateWorksheet
> > {
> > my $self = @_;
> > #if (@_) { my $sheetname = shift; }
> > my $sheetname = shift;
>
> Change those lines to this:
> my ($self, $sheetname) = @_;
>
> Or you could do this:
> my $self = shift;
> my $sheetname = shift;
>
> Or this:
> my $self = $_[0];
> my $sheetname = $_[1];
>
> > print("sheetname = $sheetname");
> > my $WorkSheet = $self->workbook->add_worksheet($sheetname); #
> > ERROR OCCURS HERE
> > $WorkSheet->set_landscape();
> > $WorkSheet->fit_to_pages(1);
> > $WorkSheet->repeat_rows(0);
> > $WorkSheet->set_header("&C" . $sheetname);
> > return my $Worksheet;
> > }
>
> HTH
|