On Oct 27, 1:52 pm, aim...@sfbrgenetics.org (Aimee Cardenas) wrote:
> Hi, All!
>
> I need to fix the width of some strings padding with leading spaces if  
> necessary.  I wanted to use printf but I don't know if you can put a  
> variable in the format part the the printf statement.  For example, if  
> I wanted to use the following format type:
>
> printf OFILE "%7s\n", $str;
>
> but instead of '7' have a variable such as $w there, how might I do  
> this?  Or is there a better function for what I'm trying to do?


my $width = 7;
my $fmt = "%${width}s";
printf $fmt, $str;

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to