Chinaunix

标题: 请教perl 文本处理 [打印本页]

作者: heijieweb    时间: 2016-04-29 10:39
标题: 请教perl 文本处理
oracle crs_stat 的输出:
NAME=ora.DATA.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=ONLINE on xdb1

NAME=ora.LISTENER.lsnr
TYPE=ora.listener.type
TARGET=ONLINE
STATE=ONLINE on xdb1

怎么才能把这个放到数组中,最后可以这样引用:

$service_name=$aaa[0] ->{name} ,得到ora.DATA.dg
作者: heijieweb    时间: 2016-04-29 10:48
回复 1# heijieweb

求大神现身,在线等

   
作者: jason680    时间: 2016-04-29 11:20
回复 1# heijieweb


$ perl get_crs_stat.pl
ora.DATA.dg
ora.LISTENER.lsnr


$ cat crs_stat
NAME=ora.DATA.dg
TYPE=ora.diskgroup.type
TARGET=ONLINE
STATE=ONLINE on xdb1

NAME=ora.LISTENER.lsnr
TYPE=ora.listener.type
TARGET=ONLINE
STATE=ONLINE on xdb1


$ cat get_crs_stat.pl

use strict;
use warnings;


my @aCrs;
my $sCnt = -1;
my @aCrs_stat =`cat crs_stat`;    # modify by yourself
foreach(@aCrs_stat){

  next if(m/^\s+$/);
  s/^\s+|\s+$//g;
  my($sItem, $sValue) = split "=";
  ++$sCnt if($sItem eq "NAME");
  $aCrs[$sCnt]->{$sItem} = $sValue;
}
  print "$aCrs[0]->{'NAME'}\n";
  print "$aCrs[1]->{'NAME'}\n";


   
作者: heijieweb    时间: 2016-04-29 11:30
jason680,果然高人,非常感谢!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2