Wednesday, March 16, 2016

perl 에서 텍스트파일 전체를 스트링으로 불러오는 법

다음과 같이 하면 됨.

use File::Slurp;
my $file_content = read_file('text_document.txt');

윈도우의 CRLF 개행문자를 처리해주려면 읽을때 다음과 같이 해줌

$text =~ s/\r\n/\n/g;

저장할때는 다음과 같이 변환해주면 됨

$text =~ s/\n/\r\n/g;

키워드 : text file, whole, load, windows, return characters
레퍼런스 : Read an entire file into a string

No comments:

Post a Comment