나는 여기 소수 일지 모른다. 그러나 나는 매우 많이 Perl's formats을 즐긴다. 특히 열 내의 텍스트의 긴 조각을 포장 할 수있는 같은 I ("~~^< < < < < < < < < < < < < < < <"타입의 물건). 비슷한 기능을 가진 다른 프로그래밍 언어 나 비슷한 기능을 구현하는 라이브러리가 있습니까? Ruby와 비슷한 것을 구현하는 라이브러리에 특히 관심이 있지만 다른 옵션에 대해서도 궁금합니다.Perl의 형식과 유사한 기능 및/또는 라이브러리가있는 다른 언어는 있습니까?
6
A
답변
7
FormatR 루비 펄과 같은 형식을 제공합니다.
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
은 내가 몇 년 전에 그것을 사용하는 경우 포트란에서 비슷한 일을 기억하는 것 (그러나 그것은 잘 할 수 있습니다 제 3 자 라이브러리였습니다).
Perl의 다른 옵션은 Perl6::Form
입니다.
Perl6에서 format
을 대신하는 form
함수가 있습니다. "Perl Best Practices는"format
.... 정적
- 와 함께 다음과 같은 문제를 인용 Perl5에 함께
Perl6::Form
을 사용하는 것이 좋습니다의 데미안 콘웨이 명명 된 파일 핸들 (만) - 하지 재귀 또는 재진입 여기
은,736,252 인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;
링크가 (효과적으로) 손상되었습니다. –