See the doco for sprintf for the details: 
http://perldoc.perl.org/functions/sprintf.html

You'll want to do:

printf "%-*s %10.2f\n", $W, $item, $price;



From: perl-win32-users-boun...@listserv.activestate.com 
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Daniel 
Burgaud
Sent: Saturday, August 29, 2009 8:51 AM
To: Perl-Win32-Users
Subject: Need help with printf/sprintf

Hi

I have a problem with printf/sprintf

Basically I have this code:
printf "%-50s %10.2f\n", $item, $price;

This code prints a line that is 61 chars long with the Item's name on the Left 
and Price on the right.
However, I want to make it variable width based on either screen width, or user 
input:
ie,

printf "%-$Ws %10.2f\n", $item, $price;

Obviously, this does not work. How do I code it to work like i want it?

Dan
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to