J
Justin C
I'm using Spreadsheet::WriteExcel, and (I think) I've created a
reference to the worksheet. When I try to use this elsewhere I get:
Can't call method ... on unblessed reference at ...
This is the minumum I've been able to cut the code down to (sorry it's
not shorter). The problem line is 26. As per the Spreadsheet::WriteExcel
documentation I've created the object, and it's a reference to that
object that I've passed from a subroutine to Main:: to pass on to other
subroutines.
I'm slowly getting to grips with references, I seem to be OK (mostly)
with scalar, array, and harh refs, but what is this? An object
reference? I'm working on it but I haven't got it yet. Anyway, here's
the code.
#!/usr/bin/perl
use warnings;
use strict;
use Spreadsheet::WriteExcel;
my ($worksheet, $format) = create_excel_file();
artist_chart() ;
sub artist_chart {
my ($position, $last_month, $artist) = ('7', '4', 'Banksy');
populate_spreadsheet(0, $position, $last_month, $artist);
}
sub create_excel_file {
my $fname = "/var/local/chart/boris.xls";
my $workbook = Spreadsheet::WriteExcel->new($fname);
my $ws = $workbook->add_worksheet();
my $format = set_sheet_table_borders($workbook);
return (\$ws, \$format);
}
sub populate_spreadsheet {
my $start_col = shift;
my $items = \@_;
my $row = $_[0] + 1;
$worksheet->write_row($row,$start_col,$items,$format);
}
sub set_sheet_table_borders {
my $wb = shift;
my $format = $wb->add_format(
border => 7,
);
return $format;
}
__END__
Thank you for any help you can give with this.
Justin.
reference to the worksheet. When I try to use this elsewhere I get:
Can't call method ... on unblessed reference at ...
This is the minumum I've been able to cut the code down to (sorry it's
not shorter). The problem line is 26. As per the Spreadsheet::WriteExcel
documentation I've created the object, and it's a reference to that
object that I've passed from a subroutine to Main:: to pass on to other
subroutines.
I'm slowly getting to grips with references, I seem to be OK (mostly)
with scalar, array, and harh refs, but what is this? An object
reference? I'm working on it but I haven't got it yet. Anyway, here's
the code.
#!/usr/bin/perl
use warnings;
use strict;
use Spreadsheet::WriteExcel;
my ($worksheet, $format) = create_excel_file();
artist_chart() ;
sub artist_chart {
my ($position, $last_month, $artist) = ('7', '4', 'Banksy');
populate_spreadsheet(0, $position, $last_month, $artist);
}
sub create_excel_file {
my $fname = "/var/local/chart/boris.xls";
my $workbook = Spreadsheet::WriteExcel->new($fname);
my $ws = $workbook->add_worksheet();
my $format = set_sheet_table_borders($workbook);
return (\$ws, \$format);
}
sub populate_spreadsheet {
my $start_col = shift;
my $items = \@_;
my $row = $_[0] + 1;
$worksheet->write_row($row,$start_col,$items,$format);
}
sub set_sheet_table_borders {
my $wb = shift;
my $format = $wb->add_format(
border => 7,
);
return $format;
}
__END__
Thank you for any help you can give with this.
Justin.