in reply to Formatting with sprintf

what output are you trying to get?

Please explain like this, type the actual characters my $input = ...; my $output = '....-....'; </c>

Replies are listed 'Best First'.
Re^2: Formatting with sprintf
by citabriabob (Novice) on Nov 10, 2015 at 02:11 UTC
    This is a CGI script. I am validating a credit card number ($cardNum) and trying to format it to look like this: 1234-5678-9012-3456. I have confirmed that $cardNum contains a correct, 16-digit value. All attempts have resulted in either null or all zero format (0000-0000-0000-0000). Wish I were smarter....
      I know this is somewhat off-topic. You should consider using the module Regexp::Common::CC for credit card validation. Unfortunately, the SYNOPSIS is incomplete. You have to check the source code for the complete list of supported credit cards.
      Bill
      Someone asked about the version: This is perl, v5.8.8 built for x86_64-linux-thread-multi

        5.8.8 is waaaaay old.

        That's why

        my $CCformatted = $card =~ s/....\K\B/-/gr;

        doesn't work, the /r came along in 5.14.

        my $CCformatted = join '-', $card =~ /..../g;

        should still work.