2017-12-11 11 views
2

파일에서 데이터를 추출하여 "foreach"루프를 사용하는 Linux sh 터미널에서 실행하려고합니다.하지만 Perl 반환 값은 sh 터미널을 사용하면 스크립트가 실패하는 다음 문자열을 인쇄하기 전에 새 행을 인쇄합니다. 어떻게 방지 할 수 있습니까?시스템을 사용하여 sh 터미널에 쓰고 난 후 print newline에서 Perl 프로그램을 방지하지 마십시오.

open(FILE, "input") or die("Unable to open file"); 

# read file into an array 
@data = <FILE>; 

# close file 
close(FILE); 

foreach my $x(@data) { 
    system "/granite_api.pl -type update_backdoor -project tgplp -test_id $x -turninid 4206"; 
} 

예상 출력 :

/granite_api.pl -type update_backdoor -project tgplp -test_id example -turninid 4206 

실제 출력 :

/granite_api.pl -type update_backdoor -project tgplp -test_id example 
-turninid 4206 

답변

4

@data = <FILE>; 
함께

@data에는 입력 파일의 모든 행이 들어 있습니다. 각 라인은 LF로 끝납니다. (`씹는 : 당신은 chomp in perldoc

+3

'chomp'도 목록에서 작동을 참조하십시오

foreach my $x (@data) { chomp $x; system "/granite_api.pl -type update_backdoor -project tgplp -test_id $x -turninid 4206"; } 

(즉 $/에 설정된 후행 문자 (들)을 제거) 예를 들어 chomp를 사용하여 각 $x에서 제거 할 필요 @data);''@ data'의 모든 요소를 ​​chomp합니다. – PerlDuck