At 01:33 PM 8/22/01 -0400, William A Fink wrote:
>Hello, I'm *BRAND NEW* to "the list" and have what may seem trivial to 
>some of you - but (because of the pressure here at-the-office) I'd 
>appreciate any help anyone could lend.
>
>I'm simply writing a program that will search one file for a string - if 
>the string is found, replace it.
>
>What I'm running up against is: if the string that I'm looking in contains 
>(1 or more) *'s, or +'s or .'s - I get an error.

You need to quotemeta() the string so it can be used literally in a regex.

>The line that I'm looking in is (almost) such as:  $original_ip_address = 
>deny+qfe1+tcp+*-*+0.0.0.0
>(can ya guess this is a firewall packet screen?)
>
>The syntax I'm using is:
>
>if ($looking_for =~ /$original_ip_address//) { $i += 1 }
>    print "You Found A Match !\";

The syntax you need will contain /\Q$original_ip_address\E/ (you have an 
extra / above, btw).

Yeah, the \E isn't necessary when it comes at the end but I just like to 
use both halves of paired things.

>However, the "$original_ip_address" is about  100 character line with 
>multiple +'s, *'s, and .'s in it and I receive the error:
>
>nested *?+ in regexp at ...line #, etc...
>
>Lastly - I am (will be) prompting the user for input for an IP address to 
>look for, but I know I'll run up against the variable containing .'s 
>having problems. How (is there a way) to specify that a user input such as 
>123.111.222.111 can be assigned to be '123.111.222.111' (with the single 
>quotes)
>
>As you can see, what my objective is - is to find the user's input (of an 
>IP address) in a text file, and replace that IP address, (if found) with a 
>new one. (They the user is too, prompted with.)
>
>I'm familiar enough with the s// syntax, but because of the dots, (.'s) in 
>both the variables, I know I'll run up against problems.
>
>Any help?
>
>My appreciation for your time in advance - I know how valuable all of our 
>time is.
>
>Bill
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to