sprintf problem

From: Billy N. Patton (b-patton_at_ti.com)
Date: 09/30/04


Date: Thu, 30 Sep 2004 10:17:36 -0500

My code:
$lcname = 15;
print sprintf("| %-m.ns |\n",$lcname,4,'CELL');
print sprintf("| %m.ns |\n",$lcname,4,'CELL');
print sprintf("| %mns |\n",$lcname,4,'CELL');
print sprintf("| %s |\n",'CELL');

The results:
| %-m.ns |
| %m.ns |
| %mns |
| CELL |

I need the 'CELL' left justified, padded with spaces and using $lcname
space.

The camel book Pg 223 parag 1
The various combinations are fully documented in the manpage for
printf(3), but we'll mention that m is typically the minimum length of a
field (negative for left justified), and n is precision for exponential
formats and the maximum length for other formats. Padding is typically
done with spaces for strings ...

-- 
    ___  _ ____       ___       __  __
   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
            /___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com


Relevant Pages

  • Re: renaming multiple files
    ... % need to convert cell to string for renaming ... therefore i am using sprintf!! ... Kind regards ...
    (comp.soft-sys.matlab)
  • Re: formatting question
    ... A few more lines of code showing what $Fmt and $TestStr are set to would ... 'Learning Perl', published by O'Reilly, is the standard recommendation; ... which specifies the formats for the second part, thelist part, ("% ... sprintf treats its first argument specially, and uses it to format the ...
    (comp.lang.perl.misc)
  • Re: regex to clean path
    ... > printf is so rarely needed in perl. ... > interpolation, sprintf, or formats ... ... I personally found formats to be quite cumbersome ... As nice it is to receive personal mail, ...
    (comp.lang.perl.misc)
  • Re: Format question
    ... What is the equivalent function ... >> for format or what do you recommend to a learner. ... I don't recall if sprintf() is as full featured, but formats did ...
    (comp.lang.perl.misc)
  • Re: Format question
    ... What is the equivalent function ... >> sprintf() cannot, personally. ... > I don't recall if sprintfis as full featured, but formats did ... output formats probably don't stick to 66 lines per page any longer, ...
    (comp.lang.perl.misc)