Perlの形式に似た機能やライブラリを持つ他の言語は何ですか?
質問
ここでは少数派かもしれませんが、をとても楽しんでいます。 Perlの形式。特に、列内の長いテキストを折り返すことができるのが好きです(<!> quot; ~~ ^ <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; < !> lt; <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; <!> lt; < !> lt; <!> quot; type stuff)。同様の機能を持つ他のプログラミング言語、または同様の機能を実装するライブラリはありますか? Rubyに似たものを実装するライブラリには特に興味がありますが、他のオプションにも興味があります。
解決
FormatR は、Ruby用のPerlに似た形式を提供します。
これはドキュメントの例です:
require "formatr"
include FormatR
top_ex = <<DOT
Piggy Locations for @<< @#, @###
month, day, year
Number: location toe size
-------------------------------------------
DOT
ex = <<TOD
@) @<<<<<<<<<<<<<<<< @#.##
num, location, toe_size
TOD
body_fmt = Format.new (top_ex, ex)
body_fmt.setPageLength(10)
num = 1
month = "Sep"
day = 18
year = 2001
["Market", "Home", "Eating Roast Beef", "Having None", "On the way home"].each {|location|
toe_size = (num * 3.5)
body_fmt.printFormat(binding)
num += 1
}
生成されるもの:
Piggy Locations for Sep 18, 2001
Number: location toe size
-------------------------------------------
1) Market 3.50
2) Home 7.00
3) Eating Roast Beef 10.50
4) Having None 14.00
5) On the way home 17.50
他のヒント
Fortranで何年も前に使用していたときに似たようなものを思い出すようです(ただし、サードパーティのライブラリであった可能性があります)。
Perlの他のオプションについては、 Perl6::Form
をご覧ください。
form
関数は、Perl6の format
を置き換えます。 <!> quot; Perlベストプラクティス <!> quot; <=> を使用することをお勧めします。 http://perldoc.perl.org/perlform.html "rel =" nofollow noreferrer "> <=> ....
- 静的に定義
- config <!> ampのグローバル変数に依存します。フォーマットするデータのpkg変数
- 名前付きファイルハンドルを使用する(のみ)
- 再帰的または再入不可
こちらは、Robert GambleによるRubyの例の <=> のバリエーションです。 ....
use Perl6::Form;
my ( $month, $day, $year ) = qw'Sep 18 2001';
my ( $num, $numb, $location, $toe_size );
for ( "Market", "Home", "Eating Roast Beef", "Having None", "On the way home" ) {
push @$numb, ++$num;
push @$location, $_;
push @$toe_size, $num * 3.5;
}
print form
' Piggy Locations for {>>>}{>>}, {<<<<}',
$month, $day, $year ,
"",
' Number: location toe size',
' --------------------------------------',
'{]}) {[[[[[[[[[[[[[[[} {].0} ',
$numb, $location, $toe_size;
Lisp (format ...)
関数があります。ループ、条件、およびその他の楽しいものがすべてサポートされています。
例(上記のリンクからコピー):
(defparameter *english-list*
"~{~#[~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~}")
(format nil *english-list* '()) ;' ==> ""
(format nil *english-list* '(1)) ;' ==> "1"
(format nil *english-list* '(1 2)) ;' ==> "1 and 2"
(format nil *english-list* '(1 2 3)) ;' ==> "1, 2, and 3"
(format nil *english-list* '(1 2 3 4));' ==> "1, 2, 3, and 4"