【发布时间】:2010-10-19 06:03:14
【问题描述】:
我是 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
}
但是,我真正想做的是跟踪 left 并将数值存储在该变量中。所以,之后 解析文件,我真的很想有以下变量 将 % 值存储在其中。原因是,我想 创建不同等级的饼图/条形图。
1 级 = 87.43 2 级 = 84.30
...
您能建议我应该研究的方法吗?
【问题讨论】:
-
大家好 - 感谢您的回复。但是,我必须承认我犯了一个错误,我提到它说 Grade1 - 80 % Grade2 - 80 % 等等。问题是您的解决方案使用“Grade”作为正则表达式中的选择标准。但是,这只是一个文件。我的大多数其他文件中都有单独的名称,例如:Mike 80% Shawn 60% Jason 44% 所以现在使用过滤器变得更加棘手......
标签: perl