thegoaltender has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to put data into an Array of Arrays for use in DBD::AnyData.
Since the size of the table varies, I am creating it in the following manner:

$test[0][0] = 'No'; $test[0][1] = 'Letter'; $test[0][2] = 'Roman'; $test[1][0] = 1; $test[1][1] = 'a'; $test[1][2] = 'i'; $test[2][0] = 2; $test[2][1] = 'b'; $test[2][2] = 'ii'; $test[3][0] = 3; $test[3][1] = 'c'; $test[3][2] = 'iii'; $test[4][0] = 4; $test[4][1] = 'd'; $test[4][2] = 'iv'; $test[5][0] = 5; $test[5][1] = 'e'; $test[5][2] = 'v'; $test[6][0] = 6; $test[6][1] = 'f'; $test[6][2] = 'vi'; $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'testtable', 'ARRAY', @test, 'ad_import');

This gives the following error:

Can't coerce array into hash at C:/Perl/site/lib/DBD/AnyData.pm line 247.

I don't currently see what the difference is from the following (which works):

@test = [ ['No','Letter','Roman'], [1,'a','i'], [2,'b','ii'], [3,'c','iii'], [4,'d','iv'], [5,'e','v'], [6,'f','vi'] ]; $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); $dbh->func( 'testtable', 'ARRAY', @test, 'ad_import');

Replies are listed 'Best First'.
•Re: DBD::AnyData & Array of Arrays
by merlyn (Sage) on Dec 31, 2003 at 20:25 UTC
    The difference is one level of indirection. In the first case, you have an array containing arrayrefs pointing to arrays containing strings. In the second case, you have an array containing a single element, which is an arrayref pointing to an array containing arrayrefs pointing to arrays containing strings.

    If you backwhack your first array, you'll get the same results as using the second array directly.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thanks, that did it. Jim