dポイントプレゼントキャンペーン実施中!

ファイルの内容を加工して表示するパールの-pオプションについて
インターネットを見ていたら-p0777という記載がありました。
この0777とは何の意味があるのですか。
-pオプションを使うときにいろいろ細かい設定ができるのでしょうか。

A 回答 (1件)

-p0777 というのは、-p というオプションと 777 という引数を与えた -0 オプションの複合ワザです。



>この0777とは何の意味があるのですか。

コマンドラインで perldoc perlrun とすると解説が読めます。

-0[*octal/hexadecimal*]
specifies the input record separator ($/) as an octal or
hexadecimal number. If there are no digits, the null character is
the separator. Other switches may precede or follow the digits. For
example, if you have a version of find which can print filenames
terminated by the null character, you can say this:

find . -name '*.orig' -print0 | perl -n0e unlink

The special value 00 will cause Perl to slurp files in paragraph
mode. The value 0777 will cause Perl to slurp files whole because
there is no legal byte with that value.


要するに、-0777 とすると、ファイルを行毎に切り出すようなことをしないで
丸呑みする(slurp files)ということです。
    • good
    • 0
この回答へのお礼

sakusaker7さん、ご回答ありがとうございます。
なるほど
pというオプションに0777を指定しているのではなく
0というオプションに777を指定しているのですね!

0というオプションは行の区切り文字を番号で指定できるオプションなのですが、
777番は文字が割り当てられていないため、これを利用してパールにファイルの最後まで一気に読み込ませる技だったのですね!

お礼日時:2008/09/08 13:33

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!