
我需要一系列匹配:@totalmatches
每个匹配包含6个元素(字符串):
@matches = ($chapternumber,$sentencenumber,$sentence,$grammar_relation,$argument1,$argument2)
我需要将每个元素推送到@matches数组/散列/引用中,然后将该数组/散列/引用推送到@totalmatches数组中.
基于搜索文件并基于满足标准选择字符串来找到匹配.
质询
>您将使用哪种数据结构?
>您可以将数组推入另一个数组,就像将元素推入数组一样吗?这是一种有效的方法吗?
>您可以同时推动所有6个元素,还是必须进行6次单独推送?
>使用2-D时,要循环使用:
foreach (@totalmatches) {
foreach (@matches) {
…
}
}
谢谢你的建议.
解决方法 不要将一个数组推入另一个数组.列表只是相互加入一个新列表.
使用参考列表.
#create an anonymous hash ref for each match$one_match_ref = { chapternumber => $chapternumber_value,sentencenumber => $sentencenumber_value,sentence => $sentence_value,grammar_relation => $grammar_relation_value,arg1 => $argument1,arg2 => $argument2};# add the reference of match into array.push @all_matches,$one_match_ref;# List of keys of interest@keys = qw(chapternumber sentencenumber sentence grammer_relation arg1 arg2);# walk through all the matches.foreach $ref (@all_matches) { foreach $key (@keys) { $val = $$ref{$key}; } # or pick up some specific keys my $arg1 = $$ref{arg1};} 总结 以上是内存溢出为你收集整理的Perl:初学者.我应该使用哪种数据结构?全部内容,希望文章能够帮你解决Perl:初学者.我应该使用哪种数据结构?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)