you want this
DB<150> sprintf "%d-%d-%d-%d", ('1234567890123456' =~ /(....)/g) => "1234-5678-9012-3456"

or this

DB<151> sprintf "%d%d%d%d-%d%d%d%d-%d%d%d%d-%d%d%d%d", split //, '12 +34567890123456' => "1234-5678-9012-3456"

But I'd rather prefer this

DB<153> join "-", ('1234567890123456' =~ /(....)/g) => "1234-5678-9012-3456"

TIMTOWTDI ... depends if you always make sure that the input is 16 characters long.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

kennethk++ msged me that leading 0 are a problem in the first approach

DB<160> sprintf "%d-%d-%d-%d", ('0123456789012345' =~ /(....)/g) => "123-4567-8901-2345"

this would fix it

DB<161> sprintf "%04d-%04d-%04d-%04d", ('0123456789012345' =~ /(.... +)/g) => "0123-4567-8901-2345"

but honestly, I doubt I would stick with this approach.


In reply to Re: Formatting with sprintf by LanX
in thread Formatting with sprintf by citabriabob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.