Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: substituting constants within regex?

by Zaxo (Archbishop)
on Jul 09, 2007 at 07:55 UTC ( #625577=note: print w/ replies, xml ) Need Help??


in reply to substituting constants within regex?

When you use constant Foo . . . , 'Foo' becomes the name of a sub. Inside a regex, you need to use a form which makes the sub be called by evaluation. The \Q is not helping, either.

while (<>) { s/${\NEWLINE()}$//; # should work print; }
It looks like you're dealing with foreign line ends, so you might do better to set $/ to CRLF or whatever and chomp.

In a substitute string, the /e modifier would be needed to call the sub.

After Compline,
Zaxo


Comment on Re: substituting constants within regex?
Select or Download Code
Re^2: substituting constants within regex?
by Anonymous Monk on Jul 09, 2007 at 08:07 UTC

    Thanks to both of you for your responses!

    > It looks like you're dealing with foreign line ends...

    I'm dealing with cleaning up the output of 'script' which sometimes has a ^M at EOL & '^M' in other cases. Changing $/ would be great if everything was consistent, but I see examples of both the control code & ASCII representations existing in the output.

    FWIW.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2014-09-02 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (19 votes), past polls