in reply to Counting to add space to a string
Output: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; }
'CALXXXX2345-06' 'CALIX123456-09' 'FLOR1234567-01'
|
|---|