line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Sys::UniqueID - Get a guaranteed unique identifier.
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Great for generating database keys, temporary filenames,
|
6
|
|
|
|
|
|
|
and even gets out those tough grass stains!
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Sys::UniqueID;
|
11
|
|
|
|
|
|
|
$id= uniqueid;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 AUTHOR
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
v, Ev@rant.scriptmania.comE
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SEE ALSO
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
perl(1), Sys::HostIP
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package Sys::UniqueID;
|
24
|
1
|
|
|
1
|
|
500
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
25
|
1
|
|
|
1
|
|
788
|
use Sys::HostIP;
|
|
1
|
|
|
|
|
2096
|
|
|
1
|
|
|
|
|
46
|
|
26
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT);
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
53
|
|
27
|
1
|
|
|
1
|
|
5
|
use vars qw($netaddr $idnum);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1132
|
|
28
|
|
|
|
|
|
|
require Exporter;
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
31
|
|
|
|
|
|
|
@EXPORT = qw(uniqueid);
|
32
|
|
|
|
|
|
|
$VERSION = '1.0';
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub uniqueid()
|
35
|
|
|
|
|
|
|
{
|
36
|
|
|
|
|
|
|
# absolutely ensure that id is unique: < 0x10000/second
|
37
|
0
|
0
|
|
0
|
|
|
unless(++$idnum < 0x10000) { sleep 1; $idnum= 0; }
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return sprintf '%012X.%s.%08X.%04X', time, $netaddr, $$, $idnum;
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$netaddr= sprintf '%02X%02X%02X%02X', (split /\./, hostip);
|