use UUID 'uuid'; $string = uuid(); # generate stringified UUID UUID::generate($uuid); # new binary UUID; prefer random UUID::generate_random($uuid); # new binary UUID; use random UUID::generate_time($uuid); # new binary UUID; use time UUID::unparse($uuid, $string); # stringify $uuid; system casing UUID::unparse_lower($uuid, $string); # force lowercase stringify UUID::unparse_upper($uuid, $string); # force uppercase stringify $rc = UUID::parse($string, $uuid); # map string to UUID; -1 on error UUID::copy($dst, $src); # copy binary UUID from $src to $dst UUID::compare($uuid1, $uuid2); # compare binary UUIDs UUID::clear( $uuid ); # set binary UUID to NULL UUID::is_null( $uuid ); # compare binary UUID to NULL
The generated UUIDs can be reasonably expected to be unique within a system, and unique across all systems, and are compatible with those created by the Open Software Foundation (OSF) Distributed Computing Environment (DCE) utility uuidgen.
Not very Perlish, is it? It's been like that for a long time though, so not very likely to change any time soon.
All take or return UUIDs in either binary or string format. The string format resembles the following:
1b4e28ba-2fa1-11d2-883f-0016d3cca427
Or, in terms of printf(3) format:
"%08x-%04x-%04x-%04x-%012x"
The binary format is simply a packed 16 byte binary value.
Alternately, the current time, the local ethernet MAC address (if available), and random data generated using a pseudo-random generator are used.
The previous content of $uuid, if any, is lost.
Note that the use of a pseudo-random generator may compromise the uniqueness of UUIDs generated in this fashion.
This algorithm used to be the default one used to generate UUIDs, but because of the use of the ethernet MAC address, it can leak information about when and where the UUID was generated.
This can cause privacy problems in some applications, so the generate() function only uses this algorithm if a high-quality source of randomness is not available.
The case of the hex digits returned may be upper or lower case, and is dependent on the system-dependent local default.
Returns 0 on success and -1 on failure. Additionally on failure, the content of $uuid is unchanged.
Returns 1 if NULL, and 0 otherwise.
If $src isn't a UUID, $dst is set to the NULL UUID.
Returns an integer less than, equal to, or greater than zero if $uuid1 is less than, equal to, or greater than $uuid2.
However, if either operand is not a UUID, falls back to a simple string comparison returning similar values.
Functionally the equivalent of calling generate() and then unparse(), but throwing away the intermediate binary UUID.
Some may also have more than one package available. It should be safe to install all variations. The UUID installer will then opt towards the older, faster library.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Details of this license can be found within the 'License' text file.
Rick Myers <jrm@cpan.org>.
Authors and/or previous maintainers:
Lukas Zapletal <lzap@cpan.org> Joseph N. Hall <joseph.nathan.hall@gmail.com> Colin Faber <cfaber@clusterfs.com> Peter J. Braam <braam@mountainviewdata.com>
William Faulk
gregor herrmann