Suppose I have a query like:
my $sql = "SELECT dev_name,
OID_name,
Obj_Val
FROM dev_logs";
where the table has values like
+----+------------+----------------------+---------+---------------------+
| id | dev_name | OID_name | Obj_Val | timeStamp |
+----+------------+----------------------+---------+---------------------+
| 1 | iKazatseva | ubntWlStatRssi | 29 | 2017-07-22 15:18:34 |
| 2 | iKazatseva | ubntWlStatSignal | -67 | 2017-07-22 10:12:32 |
| 3 | iKazatseva | ubntWlStatCcq | 91 | 2017-07-22 15:18:34 |
| 4 | iKazatseva | ubntWlStatNoiseFloor | -96 | 2017-07-27 16:45:24 |
+----+------------+----------------------+---------+---------------------+
How can I store the values returned by the query in a 2D-array like the following?:
+------------+----------------------+---------+
| dev_name | OID_name | Obj_Val |
+------------+----------------------+---------+
| iKazatseva | ubntWlStatRssi | 29 |
| iKazatseva | ubntWlStatSignal | -67 |
| iKazatseva | ubntWlStatCcq | 91 |
| iKazatseva | ubntWlStatNoiseFloor | -96 |
+------------+----------------------+---------+
I have tried some things but all I could get was either bind them in a 1d array like:
my @devLogsArr = $dbh->selectall_arrayref($sql);
or
my @OID_names= map {$_->[1]}
@{$dbh->selectall_arrayref($sql)};
or bind them in variables like:
$sth->bind_col(1, \$devname);
$sth->bind_col(2, \$OID);
$sth->bind_col(3, \$value);
print "$devname\t$OID\t$value\n" while $sth->fetchrow_arrayref;
my @devLogsArr;
push(@devLogsArr, (devname=> $devname, OID=> $OID, value=> $value))
while $sth->fetchrow_arrayref;
but its far from what I would like to do. I know that i can be done by querying the DB for each individual column but that would be redundant.
Is what I am asking here feasible?
Thanks in advance.