- formline PICTURE,LIST
-
This is an internal function used by
formats, 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$ACCUMULATORin English). Eventually, when a write is done, the contents of$^Aare written to some filehandle. You could also read$^Aand then set$^Aback to"". Note that a format typically does oneformlineper line of form, but theformlinefunction 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 the format 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.formlinealways 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)、 代わりにここに出力する方が簡単であることに気付くでしょう。