【发布时间】:2017-03-06 16:56:07
【问题描述】:
我在下面尝试将数据写入二维数组(array_source),但最终变成了一维数组(array_source)。下面是代码 sn-p,请查看并告诉我将其写入二维数组的方法,所以可以的。
$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 视为一维。
【问题讨论】:
标签: arrays perl multidimensional-array perlscript