Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are doing a <code>$row++</code> when you shouldn't be.</p> <p>Try this code instead as your starting point:</p> <pre><code>my %data; my $state = ""; my $school = ""; my $student = ""; my ( $row_min, $row_max ) = $worksheet-&gt;row_range(); my $row = $row_min; while ($row &lt;= $row_max) { my $cell0 = $worksheet-&gt;get_cell( $row, 0 ); my $cell1 = $worksheet-&gt;get_cell( $row, 1 ); if (defined($cell0)) { my $key = $cell0-&gt;value(); if ($key eq 'School') { $state = 'school'; $school = $cell1-&gt;value(); } elsif ($key eq 'course') { $state = 'course'; } elsif ($key eq 'teacher') { $state = 'teacher'; } elsif ($key eq 'student') { $state = 'student'); $student = $worksheet-&gt;get_cell( $row, 2 )-&gt;value(); } else { $data{$school}{$key} = $cell1-&gt;value(); } } elsif ($state eq 'course') { # process columns for course } elsif ($state eq 'teacher') { # process columns for teacher } elsif ($state eq 'student') { # process columns for student } $row++; } use Data::Dumper; print Dumper(\%data); </code></pre> <p><strong>Update:</strong></p> <p>To process the teacher rows, I would first declare a %teacher_columns hash outside the first while loop and also the $col_min and $col_max using the col_range() method. Then inside the <code>$key eq 'teacher'</code> elsif clause, I would do something like this:</p> <pre><code>%teacher_columns = (); # clear it out in case column names are different for this school for my $col (2 .. $col_max) { my $cell = $worksheet-&gt;get_cell( $row, $col ); $teacher_columns{$cell-&gt;value()} = $col if defined($cell) and $cell-&gt;value(); } </code></pre> <p>Then in the <code>state eq 'teacher'</code> elsif clause, I would do something like this:</p> <pre><code>foreach my $key (keys %teacher_columns) { my $cell = $worksheet-&gt;get_cell($row, $teacher_columns{$key}); if (defined($cell)) { # store cell data into proper location of your data hash } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload