in reply to Trying to manipulate data

update: as poj pointed out, not all the values in the row are an "answer", so you'll have to see if each value is a key in the hash.

Use a hash:

my %scores = ( 'Strongly Disagree', => 1, 'Disagree', => 2, 'Neutral' => 3, 'Agree' => 4, 'Strongly Agree' => 5 ); while ( $row = $sth->fetchrow_arrayref ) { $sheet->write_string($i, $_, $scores{ $row->[$_] } || $row->[$_], +$default_format) for (0..$#$row); $i++; }


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Trying to manipulate data
by emadmahou (Acolyte) on Jan 13, 2016 at 18:58 UTC

    My answer looks like this now

  • B937 5 5 5 5 5 5 5 5

    B631 5 5 5 3 4 5 5 5

  • can I add an extra field to the right that will add the answers and get the average like for my second value will be like this , 5+5+5+3+4+5+5+5/8 Also can I add extra row at the end to get the total of the column value and divide by the number of the values like 5+5/2

      I should think you can do both of these things. Give it a try!

      ( You probably want to declare a counter outside the loop for the grand total, and another counter within the loop to sum the fields and make a row total, which you would print out and also add to the grand total counter ...)

      The way forward always starts with a minimal test.