2013-06-06 2 views
2

Perl 라이브러리 Text :: CSV_XS를 사용할 때 내 CSV 파일의 헤더를 무시하고 싶습니다. Perl : Text :: CSV_XS가 포함 된 헤더 무시

는 것보다 이렇게하는 더 이상 적절한 방법이 다음

use Text::CSV_XS; 

open(my $fh, "<", "file.csv") or die "file.csv: $!"; 
my $csv = Text::CSV_XS->new(); 

#ignore header 
my $row = $csv->getline($fh); 

while ($row = $csv->getline($fh)) { 
    #do stuff with the rows... 
} 

답변

2

다음은 약간 더 나은 것 :

# Skip header 
$csv->getline($fh); 

while (my $row = $csv->getline($fh)) { 
    ... 
} 

그것은 피할 부적절한 범위 지정, 의심 변수를 재사용하고, 불필요한 할당.

+0

또는 :'$ csv-> column_names ($ csv-> getline ($ fh));' – ikegami

관련 문제