Solved

string searching

Posted on 2002-06-05
2
195 Views
Last Modified: 2010-05-18
here is what I want to do...


I have a flat file db with the following...


"Ryan","ryan@ryan.com"
"Bill","bill@bill.com"

etc....

I want to remove an entry by email address... what can I use to test if ryan@ryan.com is in a line, if so remove it.

open(file,"/path/data.dat");
@data = <file>;
close(file);

open(newfile,">path/data.dat");

foreach $line (@data) {

chop($line);

if (!($line contains ryan@ryan.com)) {
 print newfile "$line\n";

}
close(newfile);


thanks!
0
Comment
Question by:msknr
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 7057644
if( !($line =~ /\Qryan@ryan.com\E/) ){
    print newfile "$line\n";
}
0
 
LVL 8

Accepted Solution

by:
jhurst earned 100 total points
ID: 7065004
if ($line !~ /,\"ryan@ryan.com\"/i) {print $line}

is better for a couple of reasons:

a) it uses the !~ rather than doing the wrong test and then inverting it

b) the inclusion of the ,\" etc will ensure that an entry like: Jamesryan@tyan.com will not be recognized.  

c) the use of the /i at the end of the patern will ensure that the eMail address is case insensitive as it should be.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question