Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: unique file ID

by karlgoethebier (Curate)
on Apr 30, 2013 at 12:02 UTC ( #1031393=note: print w/ replies, xml ) Need Help??


in reply to unique file ID

Perhaps using GUIDs?

Linux etc.:

myMac:~ karl: uuidgen EBB88FE7-1262-43BD-9017-7CAEEA2E8627

Windows, using Powershell:

PS C:\Documents and settings\karl> [System.Guid]::NewGuid().ToString() 995187c6-993a-41e3-b249-e2c013d71c73

Should be unique enough. There are also some Modules for this on CPAN but i didn't use them.

Update:

I knew i saw something interesting about this some time ago: Generate GUID from a string by GrandFather.

Update 2:

Btw...i posted already some other variations on this "unique" stuff...

#!/usr/bin/perl + + use strict; use warnings; my ( @l, @u, @n, @p, $i, $j ); open( URANDOM, "</dev/urandom" ) || die $!; read( URANDOM, $_, 4 ); close URANDOM; srand( unpack( "L", $_ ) ); @l = ( "a" .. "z" ); @u = ( "A" .. "Z" ); @n = ( 0 .. 9 ); push( @p, splice( @l, int( rand(@l) ), 1 ) ) for ( 1 .. 10 ); push( @p, splice( @u, int( rand(@u) ), 1 ) ) for ( 1 .. 10 ); push( @p, splice( @n, int( rand(@n) ), 1 ) ) for ( 1 .. 2 ); for ( $i = @p ; --$i ; ) { $j = int( rand( $i + 1 ) ); next if $i == $j; @p[ $i, $j ] = @p[ $j, $i ]; } print join( "", @p ) . qq(\n); __END__ Karls-Mac-mini:monks karl$ ./random_filename.pl gRjyL1ivolIPHsJx0MCSeQ

...and i still think that this is not a bad ("easy") approach - if you don't plan to deploy world wide ;-)

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»


Comment on Re: unique file ID
Select or Download Code
Re^2: unique file ID
by tobyink (Abbot) on Apr 30, 2013 at 12:56 UTC

    I've used both Data::UUID and UUID::Tiny in the past and had good results with both. Although I've not tried it yet, Data::GUID::Any also looks good.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

      Thanks tobyink, next time i need something i will use Data::GUID::Any. Looks really good...

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-07-11 22:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (235 votes), past polls