?
Solved

string searching

Posted on 2002-06-05
2
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

762 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