Perl is returning this error when I try to run this code:

Not a HASH reference at /usr/share/perl5/Spreadsheet/WriteExcel/Worksh +eet.pm line 1798.

And I'm at a loss for where it might be. Also, as I've been faced with this before, what is the best way to track down issues when the error comes from the module itself? I looked at the code there (for the heck of it) - I'm about 99.9% sure I messed up somewhere. My 'messed up' code is below.

#!/usr/bin/perl -T use strict; use warnings; use Carp::Assert; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; use lib '/home/shawn/test/ais'; use DBConnect; my( $infile ) = $ARGV[ 0 ] =~ m/^([\ A-Z0-9_.-]+)$/ig; my( $date ) = $ARGV[ 1 ] =~ m/^([0-9-]+)$/ig; print "infile = $infile\n"; my $sth = $dbh->prepare( 'SELECT * FROM table WHERE field = ? AND YEAR(time) = ?' ) or die "QUERY FAIL: $DBI::errstr\n$!\n"; my @header = ([ "Some", "header", "fields" ]); my $parser = Spreadsheet::ParseExcel->new(); my $workbookin = $parser->parse( $infile ); if ( !defined $workbookin ) { die "Can\'t read spreadsheet: ", $parser->error(), ".\n"; } for( my $sheetcount = 0; $sheetcount < $workbookin->{SheetCount}; $she +etcount++ ) { my($name, $indata, $width) = readws( $sheetcount ); my $outfile = $name =~ /^([\ A-Z0-9_-]+)$/; my $workbookout = Spreadsheet::WriteExcel->new( $outfile . ".xls" ) +; my $worksheetout = $workbookout->add_worksheet( 'Data' ); $worksheetout->write_col( 0, 0, @$indata ); foreach my $row ( 1 .. @$indata) { my $sqldata = sqlget( $indata->[ $row ]->[ 3 ] ); if( $sqldata->[ 0 ] ) { my $worksheetout = $workbookout->add_worksheet( $indata->[ $r +ow ]->[ 0 ] ); foreach my $col ( @$width ) { $worksheetout->set_column( $col, $col, $width->[ $col ] ); } $worksheetout->write_col( 0, 0, \@header ); $worksheetout->write_col( 1, 0, @$sqldata ); } } } sub readws { # Read worksheet - return worksheet n +ame, data, and max cell width my $wsnum = $_[ 0 ]; # Count of input worksheet my $worksheetin = $workbookin->{Worksheet}[ $wsnum ]; my( @xldata, @width ); my( $row_min, $row_max ) = $worksheetin->row_range(); my( $col_min, $col_max ) = $worksheetin->col_range(); my $wsname = $worksheetin->{Name}; # Name of worksheet for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { $width[ $col ] = 0 unless $width[ $col ]; my $cell = $worksheetin->get_cell( $row, $col ); next unless $cell; $xldata[ $row ][ $col ] = $cell->unformatted() ; if( length( $xldata[ $row ][ $col ] ) > $width[ $col ] ) { $width[ $col ] = length( $xldata[ $row ][ $col ] ); } } } return( $wsname, \@xldata, \@width ); } sub sqlget { # Return sql data my $sqlin = $_[ 0 ]; $sth->execute( $sqlin, $date ); my $sqlout = $sth->selectall_arrayref; if( $sth->rows > 0) { return $sqlout; } else { return undef; } }

In reply to Spreadsheet::WriteExcel error by ag4ve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.