comand has asked for the wisdom of the Perl Monks concerning the following question:

I need to print data out (ideally) using a format which will result in the following text:
class        name              arg1=value1; arg2=value2; \
                               arg3=value3; arg4=value4; \
                               ....
                               argN=valueN
I have constructed a format picture which does most of this:
format TABLE =
@<<<<<<<<<<< @<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<< \
$class,      $name,            $args
~                              ^<<<<<<<<<<<<<<<<<<<<<<<< \
.
but I can't see how to get the *last* line of the format to be different from the others when dealing with a '^' type column. I am about to embark upon a path (to ruin) using 'formline' and $ACCUMULATOR ($^A) to post-process what comes out of the picture. This is a last resort, as multi line formats appear to be a pain when using formline directly. Has anyone here achieved a similar result using formats? - C.

Replies are listed 'Best First'.
Re: Format Question
by comand (Acolyte) on Mar 28, 2004 at 00:53 UTC
    No sooner asked than solved. Two words, two colons: Text::Reform. The above can be implemented as:
    use Text::Reform;
    
    my $TABLE = << '__FORMAT__';
    <<<<<<<<<<<< <<<<<<<<<<<<<<<<< [[[[[[[[[[[[[[[[[[[[[[[[[
    __FORMAT__
    
    sub continue_line {
        my ($text, $reqlen, $fldlen) = @_;
        if ($reqlen == $fldlen) { $text =~ m/\A(\s*\S*)(.*)/s }
        else                    { (" "x$reqlen . "\\", $text) }
    }
    
    print form
      { break => \&continue_line },
      $TABLE, $class, $name, $args;
    
    An *extremely* useful module!