I am currently working on a perl module
Im returning a hash %dbReturn to the caller. This is the final snippet of the code for the return
my $row_hash;
$x=0;
while($row_hash = $st->fetchrow_hashref) {
if($wildCard==1) {
foreach(@tables) {
my $col;
foreach $col(@$_) {
$dbReturn{$x}{$col} = $row_has
+h->{$col};
$x++;
}
}
}
else {
foreach(@fieldNames) {
$dbReturn{$x}{$_} = $row_hash->{$_};
#print "$dbReturn{$x}{$_}\n";
}
}
}
return $dbReturn;
The caller is doing
my $dbData = $dbFunctions->query($queryString)
my $something = $dbData->{}{};
I have tried putting known data into the {}{} and it does not work. I know the data in $dbReturn is present because if I call it from the module itself everything works fine.
Everything is using strict and warnings.
If I try to return the data as
return %dbReturn;
I get the following error apon execution
Can't use string ("1/8") as a HASH ref while "strict refs" in use at test.cgi line 14.
Here is a data demo datatable for $dbReturn
| $dbReturn{0} |
| $dbReturn{0}{'ID'} |
$dbReturn{0}{'Firstname'} |
$dbReturn{0}{'Lastname'} |
| 0 |
John |
Doe |
| $dbReturn{1} |
| $dbReturn{1}{'ID'} |
$dbReturn{1}{'Firstname'} |
$dbReturn{1}{'Lastname'} |
| 1 |
Jane |
Doe |
So My Question is, Im probably returning the hash wrong. How should I be returning it?
Thanks in advance
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.