我有两个数组
@one = ("1|1|the|dog|ran", "1|2|a|x|b", "2|8|e|s|e");
@two = ("1|2|a|x|b", "1|1|down|the|street", "2|8|e|s|e");
我需要用前两个“|”来匹配它们分离的元素。这样,当在 $one[0] 上时,搜索将返回 $two[1]。
每个数组中有数百万行,因此我需要最快的方法来执行此操作。
编辑: 对困惑感到抱歉。我想处理前2个“|”分隔的元素(即 1|2、2|1)作为数组的键,循环遍历第一个数组并使用该键搜索第二个数组以获取第二个数组中的值。这有帮助吗?
最佳答案
- For each record in the second array,
- Parse the record
- Add it to a hash keyed by the first two fields.
- For each record in the first array,
- Parse the record
- Look in the hash for a record with the appropriate key.
- If there is one,
- Do something with it.
关于perl - 如何从 Perl 数组中找到与第二个数组中的元素相匹配的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13403294/