What can be wrong with word count program?

I've got a question in my test: > What is wrong with program that counts number of lines and words in file? open F, $ARGV[0] || die $!; my @lines = ; my @words = map {split /\s/} @lines; printf "%8d %8d\n", scalar(@lines), scalar(@words); close(F); My conjectures are: 1. If file does not exist, program won't tell us about that. 2. If there are punctuation signs in file, program will count them, for example, in > abc cba > , , ,dce will be five word, but on the other hand `wc` outputs the same result, so it might be considered as correct behavior. 3. If `F` is a large file, it might be better to iterate over lines and not to dump it into `lines` array. Do you have any less trivial ideas?

以上就是What can be wrong with word count program?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » word

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准