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

Discussion in 'Perl Misc' started by perl Newbie, May 5, 2009.

  1. perl Newbie

    perl Newbie Guest

    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";
    }
    perl Newbie, May 5, 2009
    #1
    1. Advertising

  2. perl Newbie

    smallpond Guest

    On May 5, 2:45 pm, perl Newbie <> wrote:
    > 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?
    smallpond, May 5, 2009
    #2
    1. Advertising

  3. perl Newbie

    perl Newbie Guest

    On May 6, 1:21 am, smallpond <> wrote:
    > On May 5, 2:45 pm, perl Newbie <> wrote:
    >
    > > 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?


    Sorry about that ...

    Can't call method "value" on an undefined value at F:\Perl\excel
    \test.pl line 25.
    perl Newbie, May 5, 2009
    #3
  4. perl Newbie

    smallpond Guest

    On May 5, 5:04 pm, perl Newbie <> wrote:
    > On May 6, 1:21 am, smallpond <> wrote:
    >
    > > On May 5, 2:45 pm, perl Newbie <> wrote:

    >
    > > > 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?

    >
    > 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?
    smallpond, May 5, 2009
    #4
  5. perl Newbie

    perl Newbie Guest

    On May 6, 2:35 am, smallpond <> wrote:
    > On May 5, 5:04 pm, perl Newbie <> wrote:
    >
    >
    >
    >
    >
    > > On May 6, 1:21 am, smallpond <> wrote:

    >
    > > > On May 5, 2:45 pm, perl Newbie <> wrote:

    >
    > > > > 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?

    >
    > > 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?


    if you cannot help, better leave the post unanswered
    perl Newbie, May 6, 2009
    #5
  6. perl Newbie

    jmcnamara Guest

    On May 5, 7:45 pm, perl Newbie <> wrote:
    > 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.
    --
    jmcnamara, May 6, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian
    Replies:
    2
    Views:
    333
    Ulrich Petri
    Sep 6, 2003
  2. aidy
    Replies:
    5
    Views:
    224
    Marcin Mielżyński
    Jun 4, 2006
  3. chad phillips

    Can't call method "uri" on an undefined value

    chad phillips, Sep 15, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    304
    chad phillips
    Sep 15, 2003
  4. perl Newbie
    Replies:
    2
    Views:
    802
    perl Newbie
    May 6, 2009
  5. Arindam
    Replies:
    10
    Views:
    510
    Justin C
    Jul 19, 2010
Loading...

Share This Page