我有一个文本文件temp.txt,其中包含条目,
cinterim=3534
cstart=517
cstop=622
ointerim=47
ostart=19
ostop=20
Run Code Online (Sandbox Code Playgroud)
注意:键值对可以按新行排列,也可以一行排列在一行中.
我正在尝试使用Perl在DB中打印和存储这些值以获得相应的键.但是我收到很多错误和警告.现在我只是想打印这些值.
use strict;
use warnings;
open(FILE,"/root/temp.txt") or die "Unable to open file:$!\n";
while (my $line = <FILE>) {
# optional whitespace, KEY, optional whitespace, required ':',
# optional whitespace, VALUE, required whitespace, required '.'
$line =~ m/^\s*(\S+)\s*:\s*(.*)\s+\./;
my @pairs = split(/\s+/,$line);
my %hash = map { split(/=/, $_, 2) } @pairs;
printf "%s,%s,%s\n", $hash{cinterim}, $hash{cstart}, $hash{cstop};
}
close(FILE);
Run Code Online (Sandbox Code Playgroud)
有人可以提供帮助来完善我的计划.
我编写了一个Perl程序,它将匹配日志文件中的某些单词并将结果存储在数据库中.问题是这个程序适用于小文件,但不适用于文件大小~2GB.是否需要更改尺寸或程序?
use POSIX qw(strftime);
# load module
use DBI;
open( FILE, "/root/temp.log" ) or die "Unable to open logfile:$!\n";
$count_start = 0;
$count_interim = 0;
$count_stop = 0;
while (<FILE>) {
@test = <FILE>;
foreach $line (@test) {
if ( $line =~ m/server start/ ) {
#print "yes\n";
$count_start++;
}
elsif ( $line =~ m/server interim-update/ ) {
$count_stop++;
}
elsif ( $line =~ m/server stop/ ) {
$count_interim++;
}
}
print "$count_start\n";
print "$count_stop\n";
print "$count_interim\n";
$now_string = strftime …Run Code Online (Sandbox Code Playgroud) 我有Solaris 10,我正在尝试运行Perl程序.
我安装了两个perl版本:
/usr/bin/perl 版本5.8.4
和
/usr/local/bin/perl 版本5.12.3
我已经安装了DBI软件包(它已安装在这里/usr/perl5/site_perl/5.8.4/sun4-solaris-64int/auto/DBI/.packlist),我通过执行不同perl版本的Perl程序得到的问题是(在ubuntu中工作正常).
bash-3.00# perl temp.pl Can't locate Time/Piece.pm in @INC (@INC contains: /usr/perl5/5.8.4/lib/sun4- solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4- solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at temp.pl line 4. BEGIN failed--compilation aborted at temp.pl line 4. bash-3.00# /usr/local/bin/perl temp.pl Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.12.3 /sun4-solaris /usr/local/lib/perl5/site_perl/5.12.3 /usr/local/lib/perl5/5.12.3/sun4- solaris /usr/local/lib/perl5/5.12.3 /usr/local/lib/perl5/site_perl .) at temp.pl line5. BEGIN failed--compilation aborted at temp.pl line 5.
我已经尝试了很多方法,但没有得到如何在solaris上运行我的Perl程序.有人可以帮忙吗.
以下是我的计划.实际上它是由@Borodin重新定义的.非常感谢他.
use strict;
use warnings;
use …Run Code Online (Sandbox Code Playgroud)