如何将从数据库中检索到的数据写入二维数组,以及如何在 Perl 中将其检索回来?

How to write data retrieved from DB into 2D array and how can this be retrieved back in Perl?

我在下面尝试将数据写入二维数组(array_source),但最终写入一维数组(array_source)。下面是代码片段,请查看并告诉我将其写入二维数组的方法,使其可以是 .

$DBHd = DBI->connect( "dbi:Oracle:host=$host;port=$port;sid=$SID", $user_name, $password);
$DBSth = $DBHd->prepare("SELECT EMP_ID,sal FROM emp");
$DBSth->execute();
my @array_temp;
my @array_source; # Should be 2D array and it should contain both values
my @array_source_in; # Should contain only employee IDS alone

while (my @array= $DBSth->fetchrow_array())
{
    push (@array_source, @array[0,1]);
    push (@array_source_in, @array[0]);
};

 print "Data in source : @array_source";
   print "\n";
 print "Data in input : @array_source_in";

将数据检索到 array_source 后,如何将其与另一个二维数组进行比较并列出匹配集?

示例:

数组 1 - 源数组 [100 5100, 101 5100, 102 6000, 104 7879, 444 287299, 771 111]

数组 2 - 应与源进行比较 [100 5100, 101 5200, 102 0, 772 800, 104 7879]

数组 3 - 这应该是输出 - 单维 [100, 104]

以上数组请省去对齐,将 1 和 2 视为二维,将 3 视为一维。

push (@array_source, @array[0,1]); 应该变成 push (@array_source, [@array[0,1]]); - 你想把一个新数组推到顶层数组上。