我可能在这里是少数,但我非常喜欢Perl's formats。我特别喜欢能够一列内包裹长一段文本( “~~^< < < < < < < < < < < < < < < <” 类型的东西)。是否还有其他具有相似功能的编程语言或实现类似功能的库?我特别感兴趣的是为Ruby实现类似的任何库,但我也对任何其他选项感到好奇。其他什么语言具有与Perl格式类似的功能和/或库?
6
A
回答
7
FormatR提供的Perl样形式的Ruby。
下面是从文档的例子:
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
2
还有Lisp (format ...)
function。它支持循环,条件和一大堆其他有趣的东西。
例如(从上方连结复制):
(defparameter *english-list*
"~{~#[~;~a~;~a and ~a~:;[email protected]{~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"
13
我似乎记得类似的东西在Fortran语言时,我很多年前用它(但它很可能已经是第三方库)。
至于在Perl中的其他选项看看Perl6::Form
。
form
函数替换Perl6中的format
。达米安康威“Perl Best Practices”建议使用Perl6::Form
与Perl5中与format
....
- 静态定义
- 依靠配置& PKG瓦尔数据的全局变量,他们在
- 使用格式化援引下列问题命名文件句柄(只)
- 没有递归或可重入
这里是一个Perl6::Form
由罗伯特宝博红宝石示例的变化....
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;
相关问题
- 1. 什么其他IoC容器具有IInitializable类似功能?
- 2. UltraEdit具有类似UltraEdit的文本解析功能的编程语言或库
- 3. 类似语言功能用Perl和Ruby __END__比较
- 4. 有什么理论和/或实验编程语言功能?
- 5. 具有类似功能的组功能
- 6. JavaScript是否具有与LINQ的Select语句类似的功能?
- 7. 什么是一些跨语言库知道其他语言的人(类似于phpjs)
- 8. 什么其他的语言也有类似的语法,但不同的含义之间我++与++ i
- 9. JavaScript或jQuery是否具有与Excel VLOOKUP类似的功能?
- 10. C#(或任何其他语言)的复杂装修新语言功能
- 11. Clone Detective是否有类似的工具可用于其他语言/ IDE?
- 12. 联合体与结构体有什么不同?其他语言是否有类似的结构?
- 13. 将语言功能集成到其他语言中
- 14. Procmail是否具有小写功能或类似功能?
- 15. hawq和其他数据库之间支持的pl语言有什么不同?
- 16. 具有默认功能和其他功能的Javascript对象
- 17. Perl有什么好的自然语言分析工具?
- 18. 什么语法糖或语言功能使语言难以解析?
- 19. Perl提供的其他语言不支持哪些编译时功能?
- 20. 哪种语言具有更好的线程功能? PHP或Ruby
- 21. 其他语言的类似reCAPTCHA的Web服务
- 22. 此功能使用什么语言?
- 23. 使用Perl或任何其他语言下载批量文件
- 24. 如何为其他语言创建类似EngineYard的服务?
- 25. ,有什么方法的等同物在其他语言
- 26. Kubernetes是否具有webhook或类似的功能?
- 27. yosys具有验证功能的正式功能是什么?
- 28. 在其他语言中使用什么bean模式名称
- 29. 具有类似于jQuery功能的模块化Javascript库
- 30. iOS中是否具有与Android中的getScaledMaximumFlingVelocity类似的功能?
链接被(有效)打破。 – 2017-06-03 04:52:33