LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 06-07-2010, 09:01 AM   #1
toredo
Member
 
Registered: Feb 2009
Posts: 83

Rep: Reputation: 25
perl - multidimensional array


hello,

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

use strict;
use DBI;

...

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

...

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

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

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
toredo

-edit-
sorry, not the right forum
please change it to:
http://www.linuxquestions.org/questions/programming-9/

thanks

Last edited by toredo; 06-07-2010 at 09:04 AM.
 
Old 06-10-2010, 07:35 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740Reputation: 740
Moved to Programming
 
Old 06-11-2010, 02:26 AM   #3
PMP
Member
 
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.

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

Code:
perldoc -m Exporter
 
Old 06-11-2010, 09:29 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Slack, Debian, Mint, Puppy, Raspbian
Posts: 3,474

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

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

Code:
$data->{COLUMN_NAME};

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


Reply


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 10:59 AM
JAVA: creating a multidimensional array Garda Programming 5 08-10-2007 07:15 AM
How to allocate memory for a multidimensional array ? indian Programming 12 11-19-2004 04:37 AM
multidimensional array (php) niehls Programming 2 01-31-2003 06:34 AM
PHP: Multidimensional array problem lhoff Programming 1 06-10-2002 03:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:39 PM.

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