Reputation: 1381
In my code I make a string that kinda resembles an IP address, using the random_regex
function from String::Random
$ip = random_regex('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}');
This is inside of a loop and whenever it hits this line, Perl outputs:
'\.' being treated as literal '.' at ./test_data.pl line 67
'\.' being treated as literal '.' at ./test_data.pl line 67
'\.' being treated as literal '.' at ./test_data.pl line 67
How do I ignore or suppress this warning? Or perhaps modify the regex to avoid it altogether?
Upvotes: 1
Views: 114
Reputation: 385897
I can't fathom why random_regex
is issuing this warning. It makes no sense to issue it for non-word chars, much less .
.
Furthermore, it provides no mechanism for disabling it, so you'll need to hook in.
my $ip = do {
local $SIG{__WARN__} = sub {
return if $_[0] =~ /^'\\(\W)' being treated as literal '\1'/;
print(STDERR $_[0]);
};
random_regex('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
};
Upvotes: 4