in reply to Re: How to convert Excel contents into a hash table and further access the contents of that hash table ?
in thread How to convert Excel contents into a hash table and further access the contents of that hash table ?
use strict; use Spreadsheet::ParseExcel; use Data::Dumper; use warnings; my $parser=Spreadsheet::ParseExcel->new(); my $workbook=$parser->parse('C:\Perl\perl_tests\Sample.xls'); if(!defined $workbook) { die $parser->error(),".\n"; } my $worksheet=$workbook->worksheet('Sheet1'); my %student_data; for my $row(1..$worksheet->row_range) { my $super_key=$worksheet->get_cell($row,0)->value; for my $col(0..4) { my $key=$worksheet->get_cell(0,$col)->value; my $value=$worksheet->get_cell($row,$col)->value; ##here I am getting a problem## $student_data{$super_key}->{$key}=$value; } } foreach my $student_name(sort keys %student_data) { foreach my $attribute (keys%{$student_data{$student_name}}) { if($student_data{$student_name}{$attribute} eq "x") { print("$student_name-->$attribute\n"); } } print("\n"); }
it shows an error "can't call method 'value' on an undefined value. I guess it is because in some cells 'x' is not written and hence that cell is empty so it is showing me this error. I tried it when all the cells contain 'x' then it is working. What should I do in this case?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How to convert Excel contents into a hash table and further access the contents of that hash table ?
by Athanasius (Archbishop) on Oct 05, 2016 at 07:32 UTC | |
by ankit.tayal560 (Beadle) on Oct 05, 2016 at 08:12 UTC | |
by Athanasius (Archbishop) on Oct 05, 2016 at 12:46 UTC | |
|
Re^3: How to convert Excel contents into a hash table and further access the contents of that hash table ?
by Tux (Canon) on Oct 05, 2016 at 09:14 UTC |