小编c0d*_*3rs的帖子

如何使用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 …
Run Code Online (Sandbox Code Playgroud)

perl

4
推荐指数
1
解决办法
310
查看次数

将文件解析为数组

我是Perl的新手,但我想基本上读一个文件来获取一些数据.我想将这些数据解析成一个数组.为什么一个阵列?因为,我想使用数据生成图形(数据的条形图或饼图).

到目前为止,这是我的Perl代码:

#!/usr/bin/perl -w
use warnings;

#Creating an array 
my @cpu_util;

#Creating a test file to read data from
my $file = "test.txt";      
#Opening the while      
open(DATA, $file) || die "Can't open $file: $!\n";

#Looping through the end of the file
while (<DATA>) 
{
if (/(\w+)\s+\d+\s+(\d+)\.(\d+)\%/){ #Getting only the "processes"
chomp;
push @cpu_util, split /\t/; #I was hoping this would split the data at the tabs
}
}

close ($file);

foreach $value (@cpu_util) {
print $value . "\n";
}
Run Code Online (Sandbox Code Playgroud)

这是我正在阅读的文件(test.txt): …

perl

0
推荐指数
1
解决办法
1900
查看次数

如何将Perl数组中的元素四舍五入到只有两位小数?

我有一个包含几个元素的数组:

MSN = 34.3433423432434%

Chrome = 12.4343434353534%

Gtalk = 32.23233543543532%...

我将这个数组作为y轴标签传递给一个名为GD :: Graph的模块.我现在面临的问题是,图表上的数字是如此之大,以至于它们与相邻条目重叠并使其无法读取.

有没有办法可以将数组中的所有元素四舍五入到小数点后两位?并使它xx.xx%?

此外,任何熟悉使用GD :: Graph的人,您知道如何增加图表上的文字大小吗?我可以很好地增加标题/图例大小,但是'Gtalk'或'32 .23233543543532%'中的实际文本非常小,我已经尝试了很多来自http://search.cpan.org/dist/GDGraph的命令/Graph.pm,但它们似乎对我不起作用!

perl rounding labels gd-graph

-2
推荐指数
1
解决办法
1426
查看次数

标签 统计

perl ×3

gd-graph ×1

labels ×1

rounding ×1