From what I understand of your intentions, you want to:
- Pad a number (with zeroes) out to a given number of digits (printf and its sister sprintf are useful for this)
- Break the padded number up into sections (substr is made for slicing up strings)
- Reformat these sections according to your "template" (printf calls it a "format")
Here's one way to do it, step-by-step
#!/usr/bin/perl
use warnings;
use strict;
my $num = 34; #example number
my $padded_num = sprintf("%015d",$num); #Step 1: Pad the number
my $first = substr($padded_num, 0, 3); #Step 2: Break the padded numb
+er up
my $second = substr($padded_num, 3, 5);
my $third = substr($padded_num, 8, 7);
my $string = sprintf("NO-%s-%s-%s", $first, $second, $third); #Step 3:
+ Reformat the sections
print $string . "\n";
davis
Is this going out live?
No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.