我是Perl的全新手,但是我听说它对于解析文件非常好,所以我想过给它一个旋转。如何用Perl解析文件的一部分?
我有了下面的示例信息的文本文件:
High school is used in some
parts of the world, particularly in
Scotland, North America and Oceania to
describe an institution that provides
all or part of secondary education.
The term "high school" originated in
Scotland with the world's oldest being
the Royal High School (Edinburgh) in
1505.
The Royal High School was used as a
model for the first public high school
in the United States, the English High
School founded in Boston,
Massachusetts, in 1821. The precise
stage of schooling provided by a high
school differs from country to
country, and may vary within the same
jurisdiction. In all of New Zealand
and Malaysia along with parts of
Australia and Canada, high school is
synonymous with secondary school, and
encompasses the entire secondary stage
of education.
======================================
Grade1 87.43%
Grade2 84.30%
Grade3 83.00%
=====================================
我想分析该文件,并只获得数字信息。我 看着正则表达式,我想我会使用类似
if (m/^%/) {
do something
}
else {
skip the line
}
但是,我真正想要做的是保持对 左侧履带的变量,并存储在该变量的数值。所以,在解析文件 后,我真的希望有以下变量 将%值存储在它们中。原因是,我想要 创建不同等级的饼图/条形图。
Grade1 = 87.43 Grade2 = 84.30
...
难道你会建议我应该看什么方法呢?
大家好:但是,如果您遇到与困难(有时DWIMmery可能得到的方式),也可以明确地在读取文件中的行由行保持状态。不过,我必须承认错误我做了,我提到,说 Grade1 - 80% Grade2 - 80% 等。 的问题是你的解决方案利用了“级”的作为选择的标准正则表达式。但是,这只是一个文件。我的大多数其他文件,有他们个人的名字,如: 麦克80% 肖恩·60% 杰森44% 所以使得它更棘手现在使用过滤器... – c0d3rs 2010-10-18 16:32:50