[완료]perl array print 와 List::Compare 관련

ascendo의 이미지

안녕하세요

List::Compare 모듈을 이용하여

아래의 프로그램을 해보았는데

원하는 데로 결과가 나오질 않아 메일드립니다.

@ perl cluster_compare.pl cluster1.txt cluster2.txt

이렇게 실행시키면

결과가

cluster #### tab cluster#### xxxx tab xxxx tabxxxx tab .....

이렇게 나올줄 알았는데

cluster #### tab cluster#### xxxx enter xxxx enterxxxx
enter .....

이런식으로 나옵니다.

원하는 결과는 나오지만 출력 형식의 문제 가 있는데요

뭐가 잘못된건지 한번 부탁드겠습니다

제 생각으로는 array 를 프린팅할때의 문제 인것 같은데요

array 사이를 tab으로 프린팅 하는 방법도 부탁 드립니다.

#!/usr/bin/perl
#
use List::Compare;
use Inline::Files;
 
open DATA, "$ARGV[0]";
open DATA2, "$ARGV[1]";
 
 
%cluster;
 
 
while(<DATA>)
{	
	@line=split '\t',$_;
	#@{$cluster{$line[0]}}=@line[1];
	push @{$cluster{$line[0]}}, $line[1];
}
 
 
 
while(<DATA2>)
{
	@line=split ' ',$_;
#	$line[1]=~s/\W//g;
	$lc=List::Compare->new(\@{$cluster{$line[0]}},\@{$cluster{$line[1]}});
	@common=$lc->get_intersection;
	print "$line[0]\t$line[1]\t@common\n";
 
}

File attachments: 
첨부파일 크기
Plain text icon cluster1.txt574.6 KB
Plain text icon cluster2.txt27.38 KB
aero의 이미지

chomp 함수를 보세요.

ascendo의 이미지

좀 자세하게는 안될까용?

JEEN의 이미지

cluster1.txt cluster2.txt
파일들에 줄바꿈이 있을테니까... 그거 없애줘야 enter가 안들어가겠죠.
우선은...
Perl에 대한 실시간 답변을 듣고 싶으시면 irc.hanirc.org #perl에 오시면
친절하게 가르쳐 주실분들이 많을 겁니다. :-)
________
use perl;

use perl;

pung96의 이미지

파일에서 읽어들인 줄들이 줄바꿈문자(리눅스에서는 "\n")을 가지고 있기 때문에
split으로 나눠도 $line[1]의 제일뒤에 줄바꿈 문자가 남게 됩니다.
나중에 이 줄바꿈 문자가 출력되면서 요소마다 줄이 바뀌는 거지요.

while(<DATA1>){
    chomp;
    print;
}

위처럼 chomp를 하시면 줄바꿈 문자가 제거됩니다.

ascendo의 이미지

개행문자 덕분이었군요

덕분에 해결했습니다.

감사합니다.