Perl 中的第 5 版 UUID [英] Version 5 UUID in Perl

查看:26
本文介绍了Perl 中的第 5 版 UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

离题:

我是堆栈溢出的新手,我想打个招呼!

I'm new to stack overflow, and I wanted to say hello!

主题:

我正在为需要通过时间戳 time()

I'm generating a version 5 UUID for an application that needs randomized folder creation and deletion via a timestamp time() through

my $md5_UUID  = create_uuid_as_string(UUID_MD5, time."$job");

这些文件夹是在每个作业上每次运行时生成的,并在运行后被删除.如果以某种方式生成相同的 UUID,正在运行的 +-1000 个作业可能会停止.

These folders are generated per run on each job, and are deleted after running. If the same UUID is somehow generated, the +-1000 jobs that are running could halt.

是否有我可以从中提取的任何信息或任何冲突的可能性(不同的数据生成相同的 UUID)?它们真的独特吗?另外,我应该在 SHA1 和 MD5 之间使用哪个版本的 UUID?

Is there any information that I can pull from this or any possibility of collisions (different data generating the same UUID)? Are they truly unique? Also, which version of UUID should I use between SHA1 and MD5?

推荐答案

使用操作系统工具

可能有一个纯粹的 Perl 解决方案,但它可能有点矫枉过正.如果您在 Linux 系统上,您可以捕获 mktempuuidgen 的结果并在您的 Perl 脚本中使用它们.例如:

Use OS Tools

There's probably a pure Perl solution, but it may be overkill. If you are on a Linux system, you can capture the results of mktemp or uuidgen and use them in your Perl script. For example:

$ perl -e 'print `mktemp --directory`'
/tmp/tmp.vx4Fo1Ifh0

$ perl -e '$folder = `uuidgen`; print $folder'
113754e1-fae4-4685-851d-fb346365c9f0

mktemp 实用程序很好,因为除了返回目录名称之外,它还会自动为您创建目录.您还可以通过修改模板为目录赋予更有意义的名称(请参阅 man 1 mktemp);相比之下,UUID 并不擅长传达有用的语义.

The mktemp utility is nice because it will atomically create the directory for you, in addition to returning the directory name. You also have the ability to give more meaningful names to the directory by modifying the template (see man 1 mktemp); in contrast, UUIDs are not really good at conveying useful semantics.

这篇关于Perl 中的第 5 版 UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆