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

I'd like to use perl's format feature, but to have it also pad certain fields with underscores, eg to make header lines indicate the exact lenghts the values in the actual report lines take eg
format TOP = @||||||||||||||||||| @||||||||||||||||| @||||||||| $c1, $c2, $c3 . $c1 = "first column"; $c2 = " this month"; $c3 = " other data"; write;
should come out as
____first column____ ____this month____ other data
or (if spaces in the string could also be replaced:
____first_column____ ____this_month____ other_data
The idea is that the underscores make it easier to see later how long a field Is this possible? Is there maybe an internal variable containing te character used for padding when '|' us used in a format description?

Replies are listed 'Best First'.
Re: format: pad values/strings with '_'
by ikegami (Patriarch) on Jul 24, 2023 at 14:24 UTC

    I'd like to use perl's format feature

    I've seen recommendations to use Perl6::Form over the builtin forms.

    And it does allow you to specify the fill character. (Search for lfill and rfill.)