立即解析Perl INC中的服务票证数据和简短描述
我试图将原始的Service now票证数据解析为INC编号和简短描述。 下面的脚本不会抛出错误;然而,它并没有给我想要的立即解析Perl INC中的服务票证数据和简短描述,perl,Perl,我试图将原始的Service now票证数据解析为INC编号和简短描述。 下面的脚本不会抛出错误;然而,它并没有给我想要的 #!/usr/bin/perl use warnings; use strict ; #my $rawTicket = "$ARGV[0]" ; my $line = ""; my $incnumb = ""; #open my $ticketPaste, '<', $rawTicket or die "Failed to open $rawTicket: $!\
#!/usr/bin/perl
use warnings;
use strict ;
#my $rawTicket = "$ARGV[0]" ;
my $line = "";
my $incnumb = "";
#open my $ticketPaste, '<', $rawTicket or die "Failed to open $rawTicket: $!\n";
#while( $line = <$ticketPaste> ) {
while( $line = <DATA> ) {
next if $line =~ /^$/ ;
next if $line =~ /\(empty\)/ ;
if ($line =~ /Select record for action.* Preview (INC\d+)/) {
$incnumb = $1;
}
next if $line =~ /Select record for action/ ;
print "$incnumb $line\n" ;
#sleep 1 ;
}
# close $ticketPaste or die "Failed to close $rawTicket: $!\n";
##Can't use string (" ") as a symbol ref while "strict refs" in use at ./ticket_watch.pl line 18, <$ticketPaste> line 7. <!-- did not like the 'my line' in line 7
__END__
(empty)
Ctas
?Select record for action ?Preview INC1008626119
(empty)
(empty)
(empty)
RE: RPM 117036-2 - New Service Request for CASPER
?Select record for action ?Preview INC1008625854
(empty)
(empty)
然而,这正是我想要得到的:
casper@CASPER ~$ ./rawTicketParse.pl
INC1008626119 Ctas
INC1008625854 RE: RPM 117036-2 - New Service Request for CASPER
您需要修复正则表达式并跟踪上一行,以便可以预先输入数字:
use warnings;
use strict ;
my $prevline;
while (my $line = <DATA> ) {
next if $line =~ /^$/ ;
next if $line =~ /\(empty\)/ ;
if ($line =~ /Select record for action.*Preview (INC\d+)/) {
my $incnumb = $1;
print "$incnumb $prevline\n" ;
}
$prevline = $line;
}
使用警告;
严格使用;
我的$prevline;
while(我的$line=){
下一步如果$line=~/^$/;
如果$line=~/\(空\)则下一步;
如果($line=~/选择操作记录。*预览(INC\d+/){
my$incnumb=$1;
打印“$incnumb$prevline\n”;
}
$prevline=$line;
}
您的正则表达式与您认为的行不匹配,因为它在单词Preview之前需要一个空格,而您的输入没有空格。好吧,我错过了,因为某种原因,现在跳过了第一条记录。
use warnings;
use strict ;
my $prevline;
while (my $line = <DATA> ) {
next if $line =~ /^$/ ;
next if $line =~ /\(empty\)/ ;
if ($line =~ /Select record for action.*Preview (INC\d+)/) {
my $incnumb = $1;
print "$incnumb $prevline\n" ;
}
$prevline = $line;
}