L
Larry W. Virden
I have some legacy code, the author of whom is no longer available for
consultation.
Here is a piece of the code in question:
:
up here, the DBI connection to the database, the select statement,
etc. occurs
:
# put results of query into single array and return
while (@next_row= $query->fetchrow_array()){
push(@array_result,@next_row);
}
$query->finish;
$dbconn->disconnect();
return \@array_result;
I am a perl novice. I am trying to figure out a readable approach to
dealing with the value that is returned.
One piece of code that I've bubble-gummed and bailing wired together
basically does this:
$super_list = thefunction($argument);
my $tot = scalar(@$super_list);
if ( $tot_supers >= 1 ) {
for (my $staff=0; $staff < $tot_supers; $staff++ ) {
if ( defined( $super_list->[$staff]{'User_Name'} ) ) {
$super_login = $super_list->[$staff]
{'User_Name'};
chomp($super_login);
print $super_login . "\n" ;
} else {
print "Unable to identify user $staff \n";
}
}
}
The main concern I have here is that if I want to write a "print all
columns of data" type routine, I would have to hand code a series of
if (defined...) type statements, differing depending on what table is
being dumped.
Is there another approach that would allow me to dynamically generate
the columns from the hash and then loop through them?
I apologize from the vague description - I'm still working on
understanding the data structure , etc.
consultation.
Here is a piece of the code in question:
:
up here, the DBI connection to the database, the select statement,
etc. occurs
:
# put results of query into single array and return
while (@next_row= $query->fetchrow_array()){
push(@array_result,@next_row);
}
$query->finish;
$dbconn->disconnect();
return \@array_result;
I am a perl novice. I am trying to figure out a readable approach to
dealing with the value that is returned.
One piece of code that I've bubble-gummed and bailing wired together
basically does this:
$super_list = thefunction($argument);
my $tot = scalar(@$super_list);
if ( $tot_supers >= 1 ) {
for (my $staff=0; $staff < $tot_supers; $staff++ ) {
if ( defined( $super_list->[$staff]{'User_Name'} ) ) {
$super_login = $super_list->[$staff]
{'User_Name'};
chomp($super_login);
print $super_login . "\n" ;
} else {
print "Unable to identify user $staff \n";
}
}
}
The main concern I have here is that if I want to write a "print all
columns of data" type routine, I would have to hand code a series of
if (defined...) type statements, differing depending on what table is
being dumped.
Is there another approach that would allow me to dynamically generate
the columns from the hash and then loop through them?
I apologize from the vague description - I'm still working on
understanding the data structure , etc.