Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

format

ruby

perl

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.

like image 809
Andru Luvisi Avatar asked Oct 25 '08 16:10

Andru Luvisi


1 Answers

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;
like image 53
draegtun Avatar answered Nov 15 '22 08:11

draegtun