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

Monks,

I'm reading in an sql statement via while (@data = $dbh->dbnextrow). In this loop, I'm assigning strings to each data element.
$id=$data[0]; $name=$data[1]; $text=$data[2]; $subject=$data[3];
When I go to pring out some of the variables, like $text, the output is ARRAY(0x23da8c). This happens for some of the strings, not all of them. Can anyone tell me what's going on? The columns I'm extracting are described as text fields in the table.

Thanks,
Louis

Replies are listed 'Best First'.
Re: Array 0x
by hardburn (Abbot) on Nov 04, 2003 at 18:49 UTC

    You're getting references back instead of the actual array. You could visually check the data structure you get back using Data::Dumper to see how the data is actually stored and then redo the code as needed.

    Where do you get dbnextrow() from? It's not in the DBI documentation. I suspect what you actually want is $dbh->fetchrow_array().

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      The dbnextrow() is from the Sybase::Sybperl module. I will check out the Data::Dumper.

      Thanks,
      Louis
Re: Array 0x
by etcshadow (Priest) on Nov 04, 2003 at 20:18 UTC
    It's also a possibility that there was a mess up with a perl script that inserted the values in the first place, and that the data in the DB is actually strings of "ARRAY(0x...)". In other words, that the stringification of an array-reference happened *before insert* and not *after select*.

    Just another case to investigate, if using Data::Dumper to verify your output data's structure doesn't help. Also, don't forget to read perldoc perlref and perldoc perlreftut if any of this is non-obvious to you.


    ------------
    :Wq
    Not an editor command: Wq
      I would also highly recommend perldoc perldsc.
Re: Array 0x
by jdtoronto (Prior) on Nov 04, 2003 at 18:54 UTC
    Isn't dbnextrow in the DB library for C from Microsoft?

    jdtoronto

Re: Array 0x
by mpeppler (Vicar) on Nov 05, 2003 at 18:31 UTC
    I think etcshadow is on the right track. Your assignment from @data to $id, etc. looks fine to me, and dbnextrow() shouldn't return any references when called in this manner.

    My guess is that a reference got inserted as a string - you can check this by using isql or some other basic query tool and run the same query to check the data in the database.

    Michael