Author: spadkins
Date: Tue Oct 27 16:09:41 2009
New Revision: 13437
Modified:
p5ee/trunk/App-Repository/lib/App/Repository.pm
Log:
added rows_to_hashes() method
Modified: p5ee/trunk/App-Repository/lib/App/Repository.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository.pm Tue Oct 27 16:09:41 2009
@@ -1275,6 +1275,47 @@
}
#############################################################################
+# rows_to_hashes()
+#############################################################################
+
+=head2 rows_to_hashes()
+
+ * Signature: $hashes = $rep->rows_to_hashes($rows, $cols);
+ * Param: $rows ARRAY of ARRAYs
+ * Param: $cols ARRAY,undef
+ * Return: $hashes ARRAY of HASH
+ * Throws: App::Exception::Repository
+ * Since: 0.50
+
+ Sample Usage:
+
+ $hashes = $rep->rows_to_hashes($rows, \...@cols);
+
+tbd.
+
+=cut
+
+sub rows_to_hashes {
+ &App::sub_entry if ($App::trace);
+ my ($self, $rows, $cols) = @_;
+ my $hashes = [];
+ my ($hash, $row, $col, $value);
+ if ($rows && $#$rows > -1) {
+ foreach $row (@$rows) {
+ $hash = {};
+ for (my $idx = 0; $idx <= $#$cols; $idx++) {
+ $col = $cols->[$idx];
+ $value = $row->[$idx];
+ $hash->{$col} = $value;
+ }
+ push(@$hashes, $hash);
+ }
+ }
+ &App::sub_exit($hashes) if ($App::trace);
+ return($hashes);
+}
+
+#############################################################################
# get_object()
#############################################################################