• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

使用perl统计单词(字母)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

使用perl统计字数,使用正则表达式和hash

首先去掉非显示字符(换行 空格)

其次把大写转换为小写

word.txt 原文

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Perl中文编码的处理发布时间:2022-07-22
下一篇:
在notepad++中运行perl和python的方法发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap