其他什么语言具有与Perl格式类似的功能和/或库? [英] What other languages have features and/or libraries similar to Perl's format?

查看:147
本文介绍了其他什么语言具有与Perl格式类似的功能和/或库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能在这里是少数,但我非常喜欢 Perl的格式。我尤其喜欢能够将一长段文本包装在一列中(~~~)。 <类型的东西)。是否还有其他具有相似功能的编程语言或实现类似功能的库?我特别感兴趣的是为Ruby实现类似的库,但我也很好奇任何其他选项。

FormatR 为Ruby提供类似Perl的格式。



下面是一个文档示例:

pre $ $ $ $ $ $ $


$ b $ top_ex =<< DOT
用于@的小猪位置<< @#,@ ###
月,日,年

数字:位置脚趾大小
----------------- --------------------------
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烤牛肉,没有,在回家的路上)每个{| location |
toe_size =(num * 3.5)
body_fmt.printFormat(binding)
num + = 1
}

其中产生:

  2001年9月18日的Piggy Locations 

数字:位置脚趾大小
------------------------------------ -------
1)市场3.50
2)家庭7.00
3)吃烤牛肉10.50
4)没有14.00
5)回家的路上17.50


I may be in the minority here, but I very much enjoy Perl's formats. I especially like being able to wrap a long piece of text within a column ("~~ ^<<<<<<<<<<<<<<<<" type stuff). Are there any other programming languages that have similar features, or libraries that implement similar features? I am especially interested in any libraries that implement something similar for Ruby, but I'm also curious about any other options.

解决方案

FormatR provides Perl-like formats for Ruby.

Here is an example from the documentation:

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
}

Which produces:

   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

这篇关于其他什么语言具有与Perl格式类似的功能和/或库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆