- formline PICTURE,LIST
-
This is an internal function used by
format
s, though you may call it, too. It formats (see perlform) a list of values according to the contents of PICTURE, placing the output into the format output accumulator,$^A
(or$ACCUMULATOR
in English). Eventually, when awrite
is done, the contents of$^A
are written to some filehandle. You could also read$^A
and then set$^A
back to""
. Note that a format typically does oneformline
per line of form, but theformline
function itself doesn't care how many newlines are embedded in the PICTURE. This means that the~
and~~
tokens treat the entire PICTURE as a single line. You may therefore need to use multiple formlines to implement a single record format, just like theformat
compiler.これは、
format
が使用する内部関数ですが、直接呼び出すことも できます。 これは、PICTURE の内容にしたがって、LIST の値を整形し (perlform を 参照してください)、結果をフォーマット出力アキュムレータ$^A
(English モジュールでは$ACCUMULATOR
) に納めます。 最終的に、write
が実行されると、$^A
の中身が、何らかのファイルハンドルに書き出されます。 また、自分で$^A
を読んで、$^A
の内容を""
に戻してもかまいません。 format は通常、1 行ごとにformline
を 行ないますが、formline
関数自身は、PICTURE の中に いくつの改行が入っているかは、関係がありません。 これは、~
と~~
トークンは PICTURE 全体を一行として扱うことを意味します。 従って、1 レコードフォーマットを実装するためにはformat
コンパイラのような複数 formline を使う必要があります。Be careful if you put double quotes around the picture, because an
@
character may be taken to mean the beginning of an array name.formline
always returns true. See perlform for other examples.ダブルクォートで PICTURE を囲む場合には、
@
という文字が 配列名の始まりと解釈されますので、注意してください。formline
は常に真を返します。 その他の例については perlform を参照してください。If you are trying to use this instead of
write
to capture the output, you may find it easier to open a filehandle to a scalar (open my $fh, ">", \$output
) and write to that instead.出力を捕捉するために
write
の代わりにこれを 使おうとした場合、スカラにファイルハンドルを開いて (open my $fh, ">", \$output
)、 代わりにここに出力する方が簡単であることに気付くでしょう。