欢迎来到天天文库
浏览记录
ID:40562381
大小:15.41 KB
页数:3页
时间:2019-08-04
《perl实现词频统计实验报告》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验二实验报告一、源程序:在C:ProgramFilesDzSoftPerlEditor(默认)目录下建立“words.txt”文档。#!/usr/bin/perlopen(FILE,"words.txt")ordie"filecan'tload$!";while($key=){chomp($key);$words{$key}++;}close(FILE);foreach$key(sortkeys%words){print$key,"t",$words{$key},"";}二、程序分析及注意事项(括号内内容):1
2、.open(FILE,"words.txt")ordie"filecan'tload$!";打开txt文档“words”(在默认文件夹中,若在其他文件夹中需要写明详细路径),如果打开失败,输出“filecan'tload$!”;2.$key=从文件中读取一行赋值给$key。(单独表示赋值给默认$_);3.chomp($key);去除$key末尾的回车;(chomp();默认将$_末尾的回车去掉,如果在程序中不使用默认变量,注意()内要标明目的变量);4.$words{$key}++;若出现相同的$key值,则给H
3、ASH数组value项加一;5.foreach$key(sortkeys%words){print$key,"t",$words{$key},"";}遍历HASH数组并打印结果。三、运行结果:This2a1a3address1an2and1argues1as2assistants1based1best1by1can1communications1conditions1consumer1consumer2consumers1consumers1created1decisions1develops1element1emerging1e
4、xperience1free1help1identify1idiosyncratic1important2in2increasingly1information1information1is2issues1market1marketing1match1mix1model1new2normative1of2on1online1online1paper1paper1personal1phenomenon1playing1product2products1purchase1related1review1review1role1sales1se
5、rve1several1strategic1that3the2their1to3type2usage1usage1users1word-of-mouth1work1
此文档下载收益归作者所有