Here is a version that is more dynamic but assumes data is columns A and B starting from row 1:
School 1 Dean John No.stu. 55 School 2 Dean Tony No. Students 60 School 3 Dean James No.stu. 56 No. Teacher 20
Most of the code is taken from amon's example on stackoverflow.com
use strict; use warnings; use Spreadsheet::ParseExcel; my ($infile) = @ARGV; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($infile); die $parser->error unless defined $workbook; my ($worksheet) = $workbook->worksheets(); my %data; # accumulate data here my $row = 0; my $school = 0; while(1){ my $cell = $worksheet->get_cell($row, 0); last unless defined($cell); my $key = $cell->value(); my $data = $worksheet->get_cell($row++, 1)->value(); if( $key eq "School" ) { $school = $data; } else { $data{$school}{$key} = $data; } } # see what we got foreach my $s (sort keys %data) { print "School $s:\n"; foreach my $fact (sort keys %{$data{$s}}) { print "\t$fact: $data{$s}{$fact}\n"; } }
which will print
School 1: Dean: John No.stu.: 55 School 2: Dean: Tony No. Students: 60 School 3: Dean: James No. Teacher: 20 No.stu.: 56
If you now add more facts underneath a school it will automatically add it to the hash.
In reply to Re: content triggered parsing in Spreadsheet-ParseExcel
by hdb
in thread content triggered parsing in Spreadsheet-ParseExcel
by qingxia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |