HELP - Spreadsheet::ParseExce - Can't call method "value" on anundefined value

P

perl Newbie

Hi,

I am getting an error message Can't call method "value" on an
undefined value at ....

I have used a print stmt print "RowL: $rowL ", $worksheet->get_cell
($rowL,6)->value(), "\n";

just to check the values it is working perfectly. But the array @qids
values are not printed in op, I think it is something to do with above
error message. Could someone please explain me what is wrong with my
code.

__CODE__

use strict;
use warnings;
use Spreadsheet::parseExcel;

my $excelfilename="data.xls";
my $datasheet="data";

my $parser = Spreadsheet::parseExcel->new();
my $workbook = $parser->Parse($excelfilename);
my $worksheet = $workbook->Worksheet($datasheet);
my ( $row_min, $row_max ) = $worksheet->row_range();
my $row;
my $rowL;
my @qids;

for $row ($row_min .. $row_max) {
if ($worksheet->get_cell($row,3)->value() =~/single choice/i)
{
$rowL=$row+1;
until ($worksheet->get_cell($rowL,0)->value()=~/
question/) {
if ($worksheet->get_cell($rowL,0)->value()=~/
column/) {
print "RowL: $rowL ", $worksheet-
get_cell($rowL,6)->value(), "\n";
push @qids, $worksheet->get_cell
($rowL,6)->value();
}
$rowL++;
}
}
}

foreach my $l (@qids) {
print $l, "\n";
}
 
S

smallpond

Hi,

I am getting an error message Can't call method "value" on an
undefined value at ....

Is this a troll? You call value 5 times in your program.
Are we supposed to guess which call is the failing one?
Do you not know that the error includes the line number?
 
P

perl Newbie

Is this a troll?  You call value 5 times in your program.
Are we supposed to guess which call is the failing one?
Do you not know that the error includes the line number?

Sorry about that ...

Can't call method "value" on an undefined value at F:\Perl\excel
\test.pl line 25.
 
S

smallpond

Sorry about that ...

Can't call method "value" on an undefined value at F:\Perl\excel
\test.pl line 25.

.... and which call to value is that? Do I have to count the lines in
your file for you?
 
J

jmcnamara

Hi,

I am getting an error message Can't call method "value" on an
undefined value at ....

I have used a print stmt print "RowL: $rowL ", $worksheet->get_cell
($rowL,6)->value(), "\n";


Hi,

If a cell doesn't contain a value then get_cell() will return undef
instead of a Cell object. In which case it isn't valid to call value()
on the undefined object.

Break your chained method calls into separate statements instead and
put in some error checking. For example:

my $cell = $worksheet->get_cell( $row, $col );

next unless $cell; # Or some other error check/response.

print "Value = ", $cell->value(), "\n";

Or do something like this:

print $cell->value() if $cell;

P.S. There is a dedicated Spreadsheet::parseExcel Google Group:
http://groups.google.com/group/spreadsheet-parseexcel

John.
--
 

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

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top