Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

ruby - What other languages have features and/or libraries similar to Perl's format?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I seem to recall something similar in Fortran when I used it many years ago (however, it may well have have been a third-party library).

As for other options in Perl, have a look at Perl6::Form.

The form function replaces format in Perl6. Damian Conway in "Perl Best Practices" recommends using Perl6::Form with Perl5 citing the following issues with format....

  • statically defined
  • rely on global variables for configuration and pkg variables for data they format on
  • uses named filehandles (only)
  • not recursive or re-entrant

Here is a Perl6::Form variation on the Ruby example by Robert Gamble....

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...