LoginSignup
1
1

More than 5 years have passed since last update.

perl での改行削除

Posted at

perl でファイルを処理するとき、改行を削除することがあります。
ファイルを作成した環境が UNIX 限定であれば、

chomp();

でいいのですが、Windows だった場合は CR だけ残ったりします。

面倒なので、

test.pl
while(<FILE>) {
    s/(\r\n|\r|\n)$//g;
    処理
}

と、書いてしまえば楽ちんです。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1