Re: Unique ID Generator
by scain (Curate) on Aug 23, 2001 at 14:38 UTC
|
What? I read your question several times, and still don't
understand what you want. Could you please make it a little
more clear.
Scott
Ahh, thank you, Masem. I get it now (at least I think so,
right, LostS?) | [reply] |
|
|
| [reply] |
Re: Unique ID Generator
by Masem (Monsignor) on Aug 23, 2001 at 14:39 UTC
|
my $uniqid = sprintf( "REG-RC-%04d", $id++ );
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important
| [reply] [d/l] |
|
|
So using the sprintf will put the $id variable where %04d is located?? Trying to figure out in what order I need to do the read and write of the ID.
| [reply] |
|
|
$id = 0;
while ($id < 50) {
print "Position ID: $positionid<br />\n";
my $positionid = sprintf( "REG-RC-%04d", $id++ );
}
This is what it printed:
Position ID: REG-RC-0000
Position ID: REG-RC-0000
Position ID: REG-RC-0000
Position ID: REG-RC-0000
Position ID: REG-RC-0000
.....
Did that 50 times...
Any Suggestions??
Billy S.
| [reply] [d/l] |
|
|
Nevermind... I am just dumb and reordered the print statement and the sprintf and it works great :)
Thank you SOOOO much :)
Billy S.
| [reply] |
|
|
The my declaration is messing things up here, as the value you set here is going to be only local to the block and AFTER the print statement, so it's lost.
Try this code:
my $id = 0;
my $positionid;
while ( $id < 50 ) {
$positionid = sprinft( "REG-RC-%04d", $id++ );
print "Position ID: $positionid<br />\n";
}
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
It's not what you know, but knowing how to find it if you don't know that's important
| [reply] [d/l] [select] |
|
|
|
|
| [reply] |
Re: Unique ID Generator
by dga (Hermit) on Aug 23, 2001 at 15:23 UTC
|
The one caveat that I can see is that when you run out of your 4 digit number that it will expand to more digits like
REG-RC-9999
REG-RC-10000
If you aren't going to have 10000 of these then you should be ok.
Otherwise you will need to do some stuff like going to REG-RD-0000 after REG-RD-9999.
| [reply] [d/l] |
|
|
Well they came to me and said I could bump it up to a 5 diget number :-P
If they get 99,999 job positions to fill in the next 4 years... Then DAMN.. That is good right??
| [reply] |
Re: Unique ID Generator
by Hofmator (Curate) on Aug 23, 2001 at 16:30 UTC
|
I thought I just mention that we have a good tutorial about (s)printf here at PM. You might want to take a look at it - there are more nice things you can do with (s)printf: Using (s)printf()
-- Hofmator
| [reply] |
Re: Unique ID Generator
by John M. Dlugosz (Monsignor) on Aug 23, 2001 at 22:49 UTC
|
Try magic increment, too.
my $ID= "0001";
foreach (1..20) {
print "REG-RC-$ID\t";
++$ID;
}
| [reply] [d/l] |
Re: Unique ID Generator
by mitd (Curate) on Aug 24, 2001 at 06:59 UTC
|
'Holy Binary Dumps'
Persistently yours File::CounterFile.
mitd-Made in the Dark
'My favourite colour appears to be grey.' | [reply] |