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)
  • Function is not defined for cell inputs.
    ... and array... ... Error using ==> fprintf ... Function is not defined for 'cell' inputs. ... use sprintf?? ...
    (comp.soft-sys.matlab)
  • Re: sprintf cell
    ... Error using ==> sprintf ... Function is not defined for 'cell' inputs. ... Steve Lord ...
    (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: decimal to binary?
    ...   BM> The sprintffamily is your friend. ... that will only generate text (hex and other formats). ... Why is sprintf not a reasonable ...
    (perl.beginners)