reference of $worksheet obj.

S

sam

Hi,

I try to use Spreadsheet::WriteExcel in my perl project, but couldn't
get the ref of $worksheet passed into a subroutine. Please see the code
below:

#!/usr/bin/perl -w

use strict;
use Spreadsheet::WriteExcel;

sub testing_sub
{
my ($myvar1,$myvar2,$worksheet,$excel_file) = @_;

$worksheet->write(0, 1, "testing") if ($worksheet and $excel_file);
print $myvar1, $myvar2;
}

sub main
{
# Create a new workbook called simple.xls and add a worksheet
my $workbook = Spreadsheet::WriteExcel->new("simple.xls");
my $worksheet = $workbook->add_worksheet();

my$excel_file = "./simple.xls";
$worksheet->write(0, 0, "Hi Excel!");

testing_sub("str1","str2",\$worksheet,$excel_file);
# testing_sub("str1","str2",\$worksheet);
}

main();

What should be the correct way to pass the ref obj of $worksheet?

thanks
Sam
 
T

Todd W

sam said:
Hi,

I try to use Spreadsheet::WriteExcel in my perl project, but couldn't
get the ref of $worksheet passed into a subroutine. Please see the code
below:

#!/usr/bin/perl -w

use strict;
use Spreadsheet::WriteExcel;

sub testing_sub
{
my ($myvar1,$myvar2,$worksheet,$excel_file) = @_;

$worksheet->write(0, 1, "testing") if ($worksheet and $excel_file);
print $myvar1, $myvar2;
}

sub main
{
# Create a new workbook called simple.xls and add a worksheet
my $workbook = Spreadsheet::WriteExcel->new("simple.xls");
my $worksheet = $workbook->add_worksheet();

my$excel_file = "./simple.xls";
$worksheet->write(0, 0, "Hi Excel!");

testing_sub("str1","str2",\$worksheet,$excel_file);
# testing_sub("str1","str2",\$worksheet);
}

main();

What should be the correct way to pass the ref obj of $worksheet?

Because $worksheet is already contains a scalar value, you dont need to take
a reference to it. In other words, drop the '\'.

Todd W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top