Reputation: 43683
My Perl code contains the following lines:
use Math::Random::Secure qw /irand/;
use String::Random;
$c = String::Random->new(rand_gen => sub {return irand($_[0]);})->randregex('[\da-f]{32}');
And I am experiencing the following warning message:
'\\' will be treated literally inside []
What that means and what I am doing wrong?
Upvotes: 1
Views: 209
Reputation: 386416
Another solution is to avoid String::Random entirely. The already-used irand
returns 32 bit integers, so you could use the following:
my $c = unpack 'H*', pack 'L*', map irand, 1..4;
As a bonus, I imagine this solution will be faster.
Upvotes: 1
Reputation: 2403
From the docs for String::Random::randregex:
Please note that the arguments to randregex are not real regular expressions. Only a small subset of regular expression syntax is actually supported .... Currently special characters inside [] are not supported.
So perhaps replace \d with 0-9
Upvotes: 1