Fred Sahakian wrote:
>
> I have data that prints to a flat file database.
> The data can sometimes be 1, 2, 3, or 4 characters in length.
> Id like to have it print a fixed length (6 characters) into the database, like this:
>
> xyz|fred |xyz
>
> instead of
>
> xyz|fred|xyz
>
> Is there a simple solution?
> I was going to count the string length and add a space after each character to make
> it equal to 6, but that might be the long way.
You could use either sprintf or pack:
$ perl -le'
@x = qw/one alongstring/;
for ( @x ) {
print "|" . sprintf( "%-6.6s", $_ ) . "|";
}'
|one |
|alongs|
$ perl -le'
@x = qw/one alongstring/;
for ( @x ) {
print "|" . pack( "A6", $_ ) . "|";
}'
|one |
|alongs|
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]