Home > Net >  How to print a variable by push in Perl?
How to print a variable by push in Perl?

Time:07-10

I'm trying to make an array variable which is pushed from an Excel file in Perl.

Excel is

my @registers=();
my $registers_num;

for (my $register_row = 0 3; $register_row < 5; $register_row  ) {
    push( @registers,  $worksheet->get_cell( $register_row, 0));
}

print "register: ", $registers[0], "\n ";
$registers_num = @registers;
print "register_num:", $registers_num, "\n ";

When I execute Perl, I got the below. I expected that the print $registers[0]= ID and $registers[1]= TOPINT, but something went wrong.

register: Spreadsheet::ParseExcel::Cell=HASH(0xd021bb8)
 register_num:2

CodePudding user response:

Assuming you are using Spreadsheet::ParseExcel, as in your previous question, the get_cell method returns a Cell object, not the value in the cell. To access the value of the cell, you should use the value method of the Cell object:

for (my $register_row = 0 3; $register_row < 5; $register_row  ) {
    my $name = $worksheet->get_cell($register_row, 0);
    push( @registers,  $name->value() );
}

This stores only the cell values ("Register Name") in the @registers array.

  •  Tags:  
  • perl
  • Related