如何计算单词对并输出文件
my $line = "The quick brown fox jumps over the lazy dog.";
while ($line =~ /(\w+)\s(?=(\w+\b))/g) {
print("$1 $2\n");
}
**到目前为止,这将输出 快速 快速棕色 Brown Fox ....
是否可以输出一个文本文件,例如: 快速:3(发生的时间) 快速棕色:2 布朗·福克斯(Brown Fox):5 ...
也许我们可以使用类似的东西
$wordcount{$word} += 1;
,但是当然,任何合理的解决方案都受到欢迎,非常感谢你们。 PS为模糊的表达道歉,因为我是一个超级初学者。
**
my $line = "The quick brown fox jumps over the lazy dog.";
while ($line =~ /(\w+)\s(?=(\w+\b))/g) {
print("$1 $2\n");
}
**So far this will output
The quick
quick brown
brown fox....
Is there a way to output a text file that also includes word count for example:
The quick: 3 (times of occurrence)
quick brown:2
brown fox:5...
Maybe we can use something like
$wordcount{$word} += 1;
but of course any plausible solutions are welcomed and thank you guys very much. P.S. apologies for the vague expression since I am a super beginner.
**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用将单词对(键)映射到出现数量(值)的哈希。
示例:
可能的输出:
You could use a hash that maps the word pair (key) to the number of occurrences (value).
Example:
Possible output: