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

dear monks

using a mysql routine in my perl-script for getting some entries from a database, instead of normal values I got returned the following array:

ARRAY(0x8792cd4)ARRAY(0x8792e18)ARRAY(0x8792f68)ARRAY(0x8793a9c)ARRAY(0x8793bec)

the same routine is used in the rest of the script, it works properly and looks like the following:
@my_matrix = read_multirow("customer_DB"); print @my_matrix;
does anybody knows what this return-code means and how to get back real data from this query?

Replies are listed 'Best First'.
Re: weired return of array-value
by tachyon (Chancellor) on Oct 22, 2004 at 22:26 UTC

    It appears the read_multirow is returning an array of array refs. See perlreftut In short each element of @my_matrix is a *reference* to an array of values.

    print "@$_\n" for @my_matrix; # short way for my $row_ref( @my_matrix ) { # longer way my @data = @$row_ref; print "@data\n"; } use Data::Dumper; print Dumper \@my_matrix; # always good to see what data structu +re looks like

    cheers

    tachyon

Re: weired return of array-value
by dga (Hermit) on Oct 22, 2004 at 22:27 UTC

    I do not know the specifics of read_multirow, but it looks like it's retuning an array of arrays. You will have to iterate over each one individually

    #... code defines @my_matrix at this point foreach my $row ( @my_matrix ) { print join(', ', @{$row}), "\n"; }

    Of course you will probably want headers for the output etc

Re: weired return of array-value
by ikegami (Patriarch) on Oct 22, 2004 at 22:27 UTC

    Sounds like a two-dimentional array?
    print @$_, $/ foreach (@my_matrix);

    Data::Dumper can help you see the format of many structures:
    use Data::Dumper; print Dumper(\@matrix);