in reply to Re: Simple formatting question for credit card number
in thread Simple formatting question for credit card number

I would use:
$number =~ s#(.{4})#$1 #g;

There should be a quick way doing this with unpack(), but the heat just got to me... ;-)

Liz

Update
Hmmm... that puts a space at the end. which may or may not be a problem. And it doesn't check for digits. So I guess this would be better:

$number =~ s#(\d{4})(?=\d)#$1 #g;
or:
$number = "@{[unpack '(A4)*', $number]}";
but that is heading towards obfuscation ;-) (thanks tedrek!)

Replies are listed 'Best First'.
Re: Re: Re: Simple formatting question for credit card number
by tedrek (Pilgrim) on Aug 12, 2003 at 20:25 UTC
    print join " ", unpack("A4A4A4A4", $number)