forked from slowe/panelshows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewID.pl
executable file
·58 lines (48 loc) · 1.1 KB
/
newID.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
$name = $ARGV[0];
open(FILE,"people/people.tsv");
@lines = <FILE>;
close(FILE);
$lookup = {};
$keys = {};
for($i = 1; $i < (@lines);$i++){
$lines[$i] =~ s/[\n\r]//g;
($id,$p,$imdb,$w,$c,$g,$ref) = split(/\t/,$lines[$i]);
$lookup{$p} = $id;
$keys{$id} = $p;
}
if($name && $lookup{$name}){
print "$name already exists with ID $lookup{$name}\n";
}
$key = generate_random_string($name);
while($keys{$key}){
$key = generate_random_string();
}
print "If you need a new key use: $key\n";
sub generate_random_string {
# Create a seed for the random number generator
# based on the numbers in the input
my $seed = $_[0];
my $length_of_randomstring = ($_[1] ? $_[1] : 8);
my $n = 0;
my $i;
if($seed){
my $a2n = {};
my @string = split("", $seed);
$seed = 0;
$n = @string;
for($i = 0; $i < @string ; $i++){
$seed += (ord($string[$i])/256)**($n-$i);
}
$seed =~ s/[^0-9]//g;
$seed =~ s/^0//g;
srand($seed);
}
my @chars=('a'..'z','0'..'9');
$n = @chars;
my $random_string;
foreach(1..$length_of_randomstring){
$random_string .= $chars[rand @chars];
}
return $random_string;
}