Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Padding out strings.

by comatose (Monk)
on Apr 13, 2000 at 19:44 UTC ( [id://7475]=note: print w/replies, xml ) Need Help??


in reply to Padding out strings.

Here's how you could use sprintf();

$value = 193; # Want 6 digits, 0 padded?? $value = sprintf ("%06d", $value); # Want 4 digits, 0 padded? $value = sprintf ("%04d", $value);

You get the idea.

Replies are listed 'Best First'.
RE: Re: Padding out strings.
by btrott (Parson) on Apr 13, 2000 at 19:57 UTC
    What do you mean, exactly, by the "first answer"? Both vroom's and my answer's define a pad subroutine that you can give a string and a length that you want the padded string to be. They accomplish the end result in different ways, but both work, and neither assume that you must know the string length beforehand.

      Blech. For some bizarre reason, I was thinking vroom's pad was having the length of the initial string passed to it, not the length of the output string. Whip me and call me an idiot.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://7475]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-28 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found