设为首页 收藏本站
查看: 640|回复: 0

[经验分享] 使用perl统计单词(字母)

[复制链接]

尚未签到

发表于 2015-12-26 08:06:10 | 显示全部楼层 |阅读模式
  使用perl统计字数,使用正则表达式和hash
  首先去掉非显示字符(换行 空格)
  其次把大写转换为小写
  word.txt 原文


DSC0000.gif DSC0001.gif


A coal factory in Anhui province. The United States will pursue opportunities to increase coal exports to China, says Pl
atts' Coal Trader International. Provided to China Daily

US expected to increase exports to China and Europe as power plants close
China's coal imports will continue from a more diversified number of sources over the long term, exerting a major influe
nce on international coal prices, according to Platts, a leading source of benchmark price assessments in the energy, pe
trochemicals and metals sectors.
James O'Connell, the editor-in-chief of Platts' Coal Trader International, which delivers price assessments for coal tra
ding in the Atlantic and Pacific markets, says that the US in particular will pursue the opportunity to increase coal ex
ports to the country.
He adds that other countries are also expected to export more coal to China, including Indonesia, Australia and Russia.
According to data from Platts, US coal exports will increase from 50 million metric tons in 2012 to 270 million tons by
2016, as the country sees a rapid development of its shale gas resources, with more bound for China and India especially
.
O'Connell says: "In the next 10 years, India will become China's biggest competitor in coal imports from Indonesia, whic
h provides thermal coal at the best prices."
The US imported about 40 million tons of coal mainly from Colombia in 2008, but it is now shutting down its coal-fired p
ower plants, and has quickly become a major coal exporter to Europe and China, he adds.
The US energy shift is similar to that in other coal-producing countries such as South Africa, which now exports about 6
2 million tons to Europe, India, Japan, South Korea and China.
O'Connell says the real positive for China is that as nations shift their emphasis away from coal-powered generation, su
pply choices open up for China, reducing coal import prices.
In the past year, 38 percent of China's coal imports were from Australia and 34 percent were from Indonesia.
It also imported from South Africa, Russia, Colombia, Canada and the US, meaning it has become the center of global coal
demand, O'Connell says.
Europe is also expected to see a huge reduction in the installed generation capacity of coal-fired power plants by 2020,
as it increases its solar power and wind power consumption, again beneficial for Chinese coal-fired power generation co
mpanies, price-wise.
China imported 290 million tons of coal in 2012, a 59 percent rise year-on-year, ranking it as the world's biggest coal
importer, according to the General Administration of Customs.
Its average imported coal price dropped 7.4 percent to $99.5 a ton in the past year.
Meanwhile, it exported 9.28 million tons of coal in 2012, a record low since 1986.
"China has become an important buyer in the international coal market over the past four to five years," O'Connell says.

"Its seaborne coal demand accounted for 20 percent of global seaborne coal trading, which was about 1 billion tons in th
e last year. China usually purchases its coal when prices are low, but its large purchases, caused by its demand, will c
ontinue to push prices higher," he says.
"Thus, we can clearly see a regulated fluctuation of international coal prices in past years."
With China's coal demand from its power generation companies expected to continue until 2020, the country's coal-buying
business with other markets such as Australia and Indonesia is expected to rise too.
A decade ago, China produced about 1.4 billion tons of coal annually at an average cost of $11 a ton. Last year, its ann
ual output reached 3.7 billion tons, but the cost for each ton of coal rose to $37.
The unit cost for Indonesian coal production is currently about $30, according to Platts.
As Chinese coal-fired power generation companies benefit from increasing amounts of cheaper imported coal, the domestic
coal industry is suffering serious overcapacity, weak demand and a huge decline in profits.
In the first four months of 2013, China imported 110 million tons of coal, a 25.6 percent rise year-on-year, at an avera
ge price of $91.6 a ton, down 17.8 percent year-on-year.
"Coal imports will continue to increase this year, and demand for imported coal will remain higher than for domestic coa
l," says Dai Bing, director of the coal industry information department at JYD Online Corp, a Beijing-based bulk commodi
ty consultancy.
"Imported coal prices are a lot more appealing than domestic ones. In the second half of the year, domestic overcapacity
will become even more serious, and a destocking process may lead to another round of coal price cuts."
The National Energy Administration is reported to be working on the drafting of new policies on the import of thermal co
al as a way of helping domestic coal producers. However, analysts suggest the policies would do little to aid the strugg
ling coal production industry.
"The overcapacity in the domestic market cannot be eased by limiting these imports because the new rules will stop the i
mport of inferior coal, not that of good-quality coal at better prices," says Liu Dongna, an analyst at Sublime China In
formation Co Ltd, a commodities consultancy in Shandong province.
View Code   



#!/usr/bin/perl -w
open(WORD,"word.txt") or die $!;
my %word;
@text=<WORD>;
close(WORD);
foreach(@text)
{
$_=~s/(^\s+|\s+$)//;
$_=lc($_);
}
#print @text;
foreach(@text)
{
while(m/([a-zA-Z])/g)
{
if(!exists $word{$1})
{
$word{$1}=1;
}
else
{
$word{$1}+=1;
}
}
}
sub display_node()   # display hash
{        
my %temp= @_;           #requir @_ not shift;
#while((my $key,my $value)=each%temp)  
foreach( sort keys %temp)  #sort hash by keys letters ASC
        {   
print "$_ =>$temp{$_}\n" ;  
}
}
&display_node(%word);
  
统计结果:
  /home/Young> perl test.pl
a =>376
b =>46
c =>231
d =>137
e =>418
f =>77
g =>61
h =>130
i =>338
j =>6
k =>12
l =>196
m =>104
n =>312
o =>386
p =>132
q =>2
r =>270
s =>268
t =>339
u =>111
v =>19
w =>49
x =>15
y =>64

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-156383-1-1.html 上篇帖子: perl中的反勾号(``),system和exec 下篇帖子: Perl 6 Essentials、Perl Cookbook 和 Perl Template Toolkit(Reship)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表