Solved

string searching

Posted on 2002-06-05
2
156 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now