有没有什么办法,当我们将一个元素推送到一个数组时,我们可以将它推送到特定的列。在perl中访问/修改数组
我试图做这样的事情。
push (@array, $val); .......$val should always go to first column.
push (@array, $val2); .......$val2 should go to second column
push (@array, $val3);........$val3 should go to third
我试着给\ t但没有得到正确的结果。
elsif ($line =~/RELATION/){
push (@mystuff, "$line" .",");
$line = &getline;
}
我的样本的txt文件看起来像这样
SEVERITY Warning
NODE OTHER "awssystem"
APPLICATION "AWS"
MSGGRP "OpC"
OBJECT "Audit"
MSGKEY "<$MSG_NODE>:hello"
ACK "<$MSG_NODE>:hello"
TEXT "Test one two three"
AUTOACTION "echo \"It has to ack after AA\" > /tmp/banack" ACTIONNODE IP 0.0.0.0 "<$OPC_MGMTSV>" ANNOTATE ACK
OPACTION "echo `hostname`" ANNOTATE
TROUBLETICKET
HELPTEXT "Hello what is this"
SEVERITY Warning
NODE OTHER "awssystem"
MSGGRP "OpC"
OBJECT "Audit"
MSGKEY "<$MSG_NODE>:hello"
MSGKEYRELATION ACK "<$MSG_NODE>:hello"
我在我的文本文件,很多类似的条目是这样的。我试图只捕获严重性,应用程序,msggrp和对象,在上面的输出应用程序丢失,所以我只需要把一个空白,如果它无法找到一个应用程序。
我的代码如下所示:
while ($#myarr > 0)
-------
---
elsif ($line =~/SEVERITY/){
push (@mystuff, "$line" .",");
$line = &getline;
}
我希望我的输出中SHLD眼线此
SEVERITY Warning APPLICATION "AWS" MSGGRP "OpC"
SEVERITY Warning MSGGRP "OpC"
但我的输出看起来像这样
SEVERITY Warning APPLICATION "AWS" MSGGRP "OpC"
SEVERITY Warning MSGGRP "OpC"
你能解释一下你想要的输出? – Toto 2012-02-23 10:14:31