title: How do I add a multidimensional array (AoA) to Excel using Perl?
body: <p>I want to add my data stored in 2x2 dimension array in Excel using Perl. I know how to open and add simple data. This I can do using for loop. But how can I do it elegantly?</p>
  
  <p>This is what I am trying to do </p>
  
  <pre><code>$sheet-&gt;Range("A1:B"."$size")-&gt;{Value} = @$data;
                                           or   @data;
                                           or   {@data};
                                           or   {\@data};
  </code></pre>
  
  <p>where <code>@data</code> is two dimensional array.</p>
  
  <pre><code># use existing instance if Excel is already running
  eval {$ex = Win32::OLE-&gt;GetActiveObject('Excel.Application')};
  die "Excel not installed" if $@;
  unless (defined $ex) {
      $ex = Win32::OLE-&gt;new('Excel.Application', sub {$_[0]-&gt;Quit;})
              or die "Oops, cannot start Excel";
  }
  
  
  # get a new workbook
  $book = $ex-&gt;Workbooks-&gt;Add;
  
  # write to a particular cell
  $sheet = $book-&gt;Worksheets(1);
  print "A1:B"."$size";
  # write a 2 rows by 3 columns range
  
  $sheet-&gt;Range("A1:B"."$size")-&gt;{Value} = @$data;
  </code></pre>