Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Counting to add space to a string

by Util (Priest)
on Sep 22, 2011 at 15:54 UTC ( [id://927411]=note: print w/replies, xml ) Need Help??


in reply to Counting to add space to a string

for my $acct ( qw( CAL2345-06 CALI123456-09 FLOR1234567-01 ) ) { my $formatted_account_id = format_account_id($acct); print "'$formatted_account_id'\n"; } sub format_account_id { my ($acct) = @_; my $padding_needed = 14 - length($acct); return $acct if $padding_needed < 1; $acct =~ m{ \A ([[:alpha:]]+) (.+) \z }msx or warn "Bad format: '$acct'" and return $acct; return $1 . ( 'X' x $padding_needed ) . $2; }
Output:
'CALXXXX2345-06' 'CALIX123456-09' 'FLOR1234567-01'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2024-04-23 08:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found