Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

A Procrustean Statement

by Zaxo (Archbishop)
on Jun 16, 2006 at 01:52 UTC ( [id://555671]=CUFP: print w/replies, xml ) Need Help??

Pad or truncate a string to a fixed length, $len, . . .

Padding is spaces; for ASCII NUL bytes use the 'a' or 'Z' format instead. 'Z' guarantees at least one NUL, for dealing with C strings.

$_ = pack 'A'.$len, $_;

Replies are listed 'Best First'.
Re: A Procrustean Statement
by ikegami (Patriarch) on Jun 16, 2006 at 05:01 UTC
    The following will pad but not truncate:
    $_ = sprintf '%-*s', $len, $_;
      Pad and truncate:
      $_ = sprintf '%-*.*s', $len, $len, $_;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found