+ -
当前位置:首页 → 问答吧 → 取出文本的内容赋值给变量

取出文本的内容赋值给变量

时间:2010-09-29

来源:互联网

文件名:freemoney.log

Table RP.ALL_AREAACCOUNT_BAL_TEST:
  108405 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                1548000 bytes(1000 rows)
Read   buffer bytes: 5120000

Total logical records skipped:          0
Total logical records read:        108405
Total logical records rejected:         0
Total logical records discarded:        0

Run began on Tue Sep 28 18:40:19 2010
Run ended on Tue Sep 28 18:40:29 2010

这么一段,如何取出
RP.ALL_AREAACCOUNT_BAL_TEST,108405,Tue Sep 28 18:40:19 2010,Tue Sep 28 18:40:29 2010
这些信息,然后放在变量
$table='RP.ALL_AREAACCOUNT_BAL_TEST';
$rows=108405;
$timefirst='Tue Sep 28 18:40:19 2010';
$timeend='Tue Sep 28 18:40:29 2010';

作者: leoxqing   发布时间: 2010-09-29

文件中这种结构只有一个还是重复出现啊

作者: 珞水的大叔   发布时间: 2010-09-29

回复 珞水的大叔


    不是重复出现的!

作者: leoxqing   发布时间: 2010-09-29

回复 leoxqing
  1. while(<DATA>){
  2.     if(/^Table\s(.*):$/){
  3.         $table = $1;
  4.         next;
  5.     }
  6.     if(/^\s+(\d+)\s+Rows successfully loaded\.$/){
  7.         $rows = $1;
  8.         next;
  9.     }
  10.     if(/^Run began on\s+(.*)$/){
  11.         $timefirst = $1;
  12.         next;
  13.     }
  14.     if(/^Run ended on\s+(.*)$/){
  15.         $timeend = $1;
  16.         next;
  17.     }
  18. }
复制代码

作者: 珞水的大叔   发布时间: 2010-09-29

#!/usr/bin/perl

use strict;
use warnings;

undef $/;
my $data = <DATA>;
$data =~ /table\s*(.*?):/i;
my ($table,$rows,$timefirst,$timeend) = ($data =~ /table\s*(.*?):.*?(\d+)\s*Rows.*?began on\s*(.*?)\n.*?ended on\s*(.*?)\n$/is);
print "Table: $table\nRows: $rows\nTimefirst: $timefirst\nTimeend: $timeend\n";
<STDIN>;

__DATA__
Table RP.ALL_AREAACCOUNT_BAL_TEST:
  108405 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.


Space allocated for bind array:                1548000 bytes(1000 rows)
Read   buffer bytes: 5120000

Total logical records skipped:          0
Total logical records read:        108405
Total logical records rejected:         0
Total logical records discarded:        0

Run began on Tue Sep 28 18:40:19 2010
Run ended on Tue Sep 28 18:40:29 2010

作者: iamlimeng   发布时间: 2010-09-29

楼上V5!

作者: leoxqing   发布时间: 2010-09-29