in reply to Re: Using (s)printf()
in thread Using (s)printf()

Ahhh, but Re-studying the article, the thought arises that the answer might lie with "sprintf()", using it to convert to a string which can be fed to string-processing functions to find the location of the '.' and to identify, and reserve, the parts before and after. Perhaps?

Replies are listed 'Best First'.
Re^3: Using (s)printf()
by AnomalousMonk (Bishop) on Aug 31, 2016 at 18:38 UTC

    Trailing whitespace can be a bit tricky. Maybe something like:

    c:\@Work\Perl\monks>perl -wMstrict -le "for my $n (qw( 0.12345 -0.12345 123456.12 -123456.12 123456.12345 -123456.12345 )) { my ($left, $right) = (7, 5); my $s = sprintf qq{%${left}s.%-${right}s}, split m{[.]}xms, $n, 2; print qq{'$s'}; } " ' 0.12345' ' -0.12345' ' 123456.12 ' '-123456.12 ' ' 123456.12345' '-123456.12345'


    Give a man a fish:  <%-{-{-{-<