in reply to Perl Problems with Digit Precision Changing on the Printf Statement

It works for me. The second one has a trailing newline that the first doesn't have, of course. You could also interpolate $digitprecision right in the format string:
printf STDOUT ("\n%${digitprecision}s\n" , $value);
Include the output you're getting from the two lines so we can see the problem.

I do find it a little odd, talking about "digit precision" when you're telling printf that you're printing a string.


We're not really tightening our belts, it just feels that way because we're getting fatter.
  • Comment on Re: Perl Problems with Digit Precision Changing on the Printf Statement
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl Problems with Digit Precision Changing on the Printf Statement
by EchoAngel (Pilgrim) on Jun 24, 2004 at 17:31 UTC
    I want the output from
    my $value = "0.03443762"; $digitprecision = 20; printf STDOUT ("\n%20s\n", $newvalue);
    I want the this printf statement to print exactly as it is
    output 0.03443762
    so how do i program this using $digitprecision = 20; I need to control the number of spacing using a variable
      Just like you did, or like I responded:
      # You did this, and it works: printf STDOUT ("\n%" . $digitprecision . "s\n", $newvalue); # I suggested this, and it works, too: printf STDOUT ("\n%${digitprecision}s\n", $newvalue);

      We're not really tightening our belts, it just feels that way because we're getting fatter.
        thanks!!!!!!!