slicks1 slicks1 - 2 months ago 5
Perl Question

Cannot get correct return value in sprintf function call

My problem is that the return value im printing is not being translated into a value.

I have the following code in a test file.

#!/usr/bin/perl -I/srv/www/jonathan/m/www
my $var = sprintf("$%.1f lbs",(77*2.20462));
print $var;

Its returning:
instead of the value i need to see.

What am i doing incorrectly here? I'm a perl newbie.


Perl uses dolar($) symbol to declare a scalar variable, you need to remove the $ symbol from the sprintf.

corrected code

my $var = sprintf("%.1f lbs",(77*2.20462));
print $var;


169.8 lbs