Perl Complete UUID example

Data::UUID🔗 module provides methods for generating UUID and UUIDs. It provides multiple features to generate 16 bytes format, binary, Hexa decimal values.

First, Install Data::UUID using cpan or cpanm in your terminal

cpanm Data::UUID
or
cpan Data::UUID

Perl UUID

UUID is a unique identifier generator used for identifying unique value for documents or objects. Data::UUID module provides different

How to check and Compare UUID are equal or not in Perl?

Data::UUID module provides compare($uuid1, $uuid1) method that checks and compare first UUID with Second UUID. It does the alphabetical letter sequence comparsision

  • It returns 0 if both are equal.
  • It returns -1 if first one is less than second
  • It returns 1 if first one is greater than second

Here is an example for comparing

use Data::UUID;
$ug    = Data::UUID->new;
$uuid1 = $ug->create_str();
$uuid2 = $ug->create_str();
print "$uuid1\n";
print "$uuid2\n";
$res   = $ug->compare($uuid1, $uuid1);
print "$res\n"; # 0
$res1   = $ug->compare($uuid1, $uuid2);
print "$res1\n";# -1
$res2   = $ug->compare($uuid2, $uuid1);
print "$res2\n";# 1

if($ug->compare($uuid1, $uuid1)== 0){
    print "equal\n";
}else{
    print "not equal\n";
}

Output:

2290D9E2-6D8E-1014-83E3-9DF9F09D57AF
2290E9BC-6D8E-1014-83E3-9DF9F09D57AF
0
-1
1
equal