I would like to write a Perl subroutine that takes either a string value or a regex value as a parameter and do different things depending on the result. For the sake of this question it simply returns "regex"
if it is a regex value and "string"
if it is not a regex:
sub value_string_or_regex {
my ($value) = @_;
my $result = '';
# magic here
return $result;
}
So the following code would print out "string
":
print(value_string_or_regex("hello world") . "\n");
And the following code would print out "regex
":
print(value_string_or_regex(qr/^.*world$/) . "\n");