Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Unique ID Generator

by Masem (Monsignor)
on Aug 23, 2001 at 14:39 UTC ( [id://107341]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Unique ID Generator

sprintf is your friend:
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

Replies are listed 'Best First'.
Re: Re: Unique ID Generator
by LostS (Friar) on Aug 23, 2001 at 14:46 UTC
    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.
Re: Re: Unique ID Generator
by LostS (Friar) on Aug 23, 2001 at 14:56 UTC

    Hey Masem... I tried this out... Can you look at this and see where I went wrong??

    $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.

      Nevermind... I am just dumb and reordered the print statement and the sprintf and it works great :)

      Thank you SOOOO much :)

      Billy S.
      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

        I got it working great :)

        It reads the file holding the ID's incrememts and the saves it :) THANK YOU

        Billy S.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://107341]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.