Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I am looking for the best structure to create to manipulate some data.and this is the code to generate itmy %struture = ( '1' => { 'field1_statement1' => 'value', 'field2_statement1' => 'value' }, '2.1' => { 'field1_statement2' => 'value', 'field2_statement2' => 'value', 'field3_statement2' => 'value' }, '2.2' => { 'field1_statement2' => 'value', 'field2_statement2' => '', 'field3_statement2' => 'value' }, '3.1' => { 'field1_statement2' => 'value' } );
What do you think? Is it relevant?my @statements; my %structure; foreach my $elt ( @statements ) { my @ex = exec($elt); my $i; for (my $y=0;$y<=$#ex;$y++) { my %results_temp = %{$ex[$y]}; my $index = "$i.$y"; foreach my $key (keys %results_temp) { $structure{$index}{$key} = $results_temp{$key}; } } } sub exec { my @param = @_; my ($type, $db, $login, $pwd, $ip) = getDBInfo(); my $dbh = connectDB ($type, $db, $login, $pwd, $ip); my @store; foreach (@param) { my $sth = $dbh->prepare ($_); $sth->execute() || die $sth->errstr; while (my $hash_ref = $sth->fetchrow_hashref) { push @store, $hash_ref; } } return @store; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best complex structure?
by merlyn (Sage) on Jun 08, 2005 at 14:20 UTC | |
by Anonymous Monk on Jun 08, 2005 at 15:24 UTC | |
|
Re: Best complex structure?
by BrowserUk (Patriarch) on Jun 08, 2005 at 17:34 UTC | |
by mrborisguy (Hermit) on Jun 08, 2005 at 18:10 UTC | |
by BrowserUk (Patriarch) on Jun 08, 2005 at 18:25 UTC | |
by Anonymous Monk on Jun 09, 2005 at 15:09 UTC | |
by BrowserUk (Patriarch) on Jun 09, 2005 at 15:26 UTC | |
| |
by BrowserUk (Patriarch) on Jun 09, 2005 at 15:36 UTC | |
|