2013-02-18 4 views

답변

1

데이터를 배열로 푸시하면됩니다.

my @errors; 
while (<>) 
{ 
    my $line = $_; 
    if ($line =~ m/ERROR 0x/) 
    { 
     push @errors, $line; 
    } 
} 

청소 일까지 약간의 :

my @errors; 
while (my $line = <>) 
{ 
    if ($line =~ /ERROR 0x/) 
    { 
     push @errors, $line; 
    } 
} 

또는 마지막으로 어쩌면

my @errors; 
while (<>) 
{ 
    if (/ERROR 0x/) 
    { 
     push @errors, $_; 
    } 
} 

, grep 큰 여기에 할 것이다 것을 깨닫게 :

my @errors = grep { /ERROR 0x/ } <>; 
+0

오타가 세 번째 예제에서, 그것은 대신에'$ _'이어야한다. '$ line'. – Toto

+0

@ M42, 그것을 고치기위한 Borodin에게 감사드립니다. – ikegami

0
my @arr; 
while (<>) 
{ 
    my $line = $_; 
    if ($line =~ m/ERROR 0x/) 
    { 
     push(@arr,$line) ; 
    } 
} 

print "$_\n" for @arr; 
관련 문제