Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: conditional string formatting

by superfrink (Curate)
on Jun 10, 2015 at 05:56 UTC ( [id://1129795]=note: print w/replies, xml ) Need Help??


in reply to conditional string formatting

You might find something in perlform. The following is close but puts the extra whitespace on the left instead of the right in the case of a length of one.

Update: In this code format is not print the trailing \s characters. Sample output updated to show the whitespace is missing.
#! /usr/bin/perl -w use strict; for my $val (qw/a ab abc abcd/) { format = @|||| $val . write \*STDOUT; }
Output:
$ ./centre-via-format.pl a ab abc abcd $ ./centre-via-format.pl | od -ch 0000000 a \n a b \n a b c \n a b c 2020 0a61 6120 0a62 6120 6362 610a 6362 0000020 d \n 0a64 0000022

Log In?
Username:
Password:

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

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

    No recent polls found