in reply to Re: Passing regular expressions as arguments to subroutines
in thread Passing regular expressions as arguments to subroutines
The only reason the subroutine must only accept a regex is because
that is the requirement imposed by the problem. Without such restriction, the
subroutine could also accept a string (in which case, one easy
way to validate would likely involve an eval() ).
The code, $string =~ $re ;, will work in both cases:
- when $re is of type Regexp, as in $re=qr/\w/i,
- when $re is just a scalar for a string, as in
- $re = '(?i-xsm:\w)', or
- $re = '\w';
|
---|
In Section
Seekers of Perl Wisdom