Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Passing regular expressions as arguments to subroutines

by ioannis (Prior)
on Nov 03, 2005 at 00:24 UTC ( #505186=note: print w/replies, xml ) Need Help??


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:

  1. when $re is of type Regexp, as in $re=qr/\w/i,
  2. when $re is just a scalar for a string, as in
    • $re = '(?i-xsm:\w)', or
    • $re = '\w';
  • Comment on Re^2: Passing regular expressions as arguments to subroutines

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://505186]
help
Chatterbox?
[finddata]: How do i perform multiple line substitution into single line for same variable using perl

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-02-24 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (352 votes). Check out past polls.