Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using a regex saved in an environment variable

by JavaFan (Canon)
on May 03, 2012 at 08:28 UTC ( #968674=note: print w/ replies, xml ) Need Help??


in reply to Using a regex saved in an environment variable

Now I want to do the same thing except put the regular expression in an environment variable:

export REX="/--Begin--/ && /--End--/" echo $REX /--Begin--/ && /--End--/
But that's not a regexp; that's an expression.

You can do the interpolation in the shell, so that Perl sees what you intent it to see:

perl -00 -ne 'print if '$REX file.txt
Here, $REX is exposed to the shell, which sees the above as:
perl -00 -ne 'print if /--Begin--/ && /--End--/' file.txt


Comment on Re: Using a regex saved in an environment variable
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2015-07-05 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls