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;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…