0

I am new to perl and having trouble with the spreadsheet excel parser module.

WHen I use $cell->value() on its own line, there appears to be no problem, however when I try to use this to insert the value into an array, it returns undef, code show below:

for my $row ($row_min .. $row_max) {
    my @line;
        for my $col ( $col_min .. $col_max) {
                my $cell = $worksheet->get_cell( $row, $col );
                $value = $cell->value;
                push @line, $value if defined($cell);
                print $cell->value;
                print Dumper $line;
                }

         }
}

Here print $cell->value; returns the contents of the cell but print Dumper $line; returns undef

James Jiimmy
  • 49
  • 1
  • 11
  • What is `$line`? Do you mean `print Dumper (\@line);` ? – RobEarl Jun 03 '15 at 10:54
  • Yes! Thanks, I was using Dumper incorrectly and the getvalue was actually working. Thanks for the help. – James Jiimmy Jun 03 '15 at 10:57
  • Exactly such errors are very easy capture using: `use strict; use warnings;` You have a happy day, because is very common than nobody bother with questions what dosen't contains use strict and use warnings;. – kobame Jun 03 '15 at 13:06

1 Answers1

2

You have to push $cell->valuenot $value

push @line, $cell->value if defined($cell);

You should add use strict at the beginning of your program, so you get an error message in such a case.

choroba
  • 231,213
  • 25
  • 204
  • 289
Jens
  • 67,715
  • 15
  • 98
  • 113