Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Reg exp with ansi

by kael (Monk)
on Jan 08, 2001 at 23:37 UTC ( [id://50557]=perlquestion: print w/replies, xml ) Need Help??

kael has asked for the wisdom of the Perl Monks concerning the following question:

ok, this is what I have
$prompt=color("blue").": ".color("reset"); unless ($line=~/\r\n$prompt$/){ $line.="\r\n$prompt"; }
This is with the Term::ANSIColor module...
The problem is this crashes complaining about an umatched []
I tried using /o but that didn't help. Why isn't whats in the variable getting escaped out and how can I tell it to get escaped?

Replies are listed 'Best First'.
Re: Reg exp with ansi
by chipmunk (Parson) on Jan 08, 2001 at 23:41 UTC
    The value of an interpolated variable in a regex is not supposed to be escaped automatically; it would be impossible to use strings as regexes that way. Instead, you can ask for the escaping when you need it, with quotemeta or \Q: unless ($line =~ /\r\n\Q$prompt\E$/) {

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://50557]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-23 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found