2

我有两个数组

@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)作为数组的键,循环遍历第一个数组并使用该键搜索第二个数组以获取第二个数组中的值。这有帮助吗?

4

1 回答 1

4
- 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.
于 2012-11-15T17:56:56.097 回答