[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

string searching

Posted on 2002-06-05
2
Medium Priority
?
216 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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

656 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