Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-07-2010, 08:01 AM   #1
Registered: Feb 2009
Posts: 83

Rep: Reputation: 25
perl - multidimensional array


i try to learn perl. but i have some problems.
i have a package with my db-"things", there is code like this:
package Database;

use strict;
use DBI;


my $dbh = DBI->connect('...');


sub select
        my @result = ();
        my @row;
        my $sth = $dbh->prepare($_[0]);
        push @result, \@row while (@row = $sth->fetchrow_array());
        return @result;

in my script i use this packe to call the select-function:

for (Database::select("SELECT PkDataType, Name, Url FROM tb_DataType;"))
        print "val: ", $_, "\n" for @{$_};
        print $#{$_}, "..\n";

now, the problem is to select the values in the arrays in the arrays^^
ths code inside the loop does nothing. i tried so many things but nothing worked... why?
how can i select the values inside the arrays of the array?

my second and small questions:
i always have to write Database::, is there a way i can onle write the funtcion-name?

best regards

sorry, not the right forum
please change it to:


Last edited by toredo; 06-07-2010 at 08:04 AM.
Old 06-10-2010, 06:35 AM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,808

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Moved to Programming
Old 06-11-2010, 01:26 AM   #3
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
1. is your query returning the expected data structure.

have a look at the module to look what is inside your data structure.

perldoc -m Data::Dumper
For your second query, have a look at following module

perldoc -m Exporter
Old 06-11-2010, 08:29 AM   #4
Senior Member
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
Don't understand what you are asking,
but as a hint...

you are possibly better off using
$data = $sth->fetchrow_hashref('NAME_uc');
then you can pull the fields out by name:


Last edited by bigearsbilly; 06-11-2010 at 08:37 AM. Reason: typo of typo!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl multidimensional array zhjim Programming 9 08-21-2009 09:59 AM
JAVA: creating a multidimensional array Garda Programming 5 08-10-2007 06:15 AM
How to allocate memory for a multidimensional array ? indian Programming 12 11-19-2004 03:37 AM
multidimensional array (php) niehls Programming 2 01-31-2003 05:34 AM
PHP: Multidimensional array problem lhoff Programming 1 06-10-2002 02:49 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration