For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2007 > Reading and matching email ids









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Reading and matching email ids
Saravana Kumar

2007-04-20, 6:58 pm

Hi list,

I am testing a regex with email ids. I have a list of ids that i want to
match against a one more list of ids.

I have this:
#! /usr/bin/perl
$id="user1@example.net";
while(<> ) {
chomp($_);print "$_\t";
print "$id found\n" if /$id/;
print "$id not found\n" if ! /$id/;
}

and a file /tmp/sampleids
user1@example.net
user2@example.net
user3@example.net
user1\@example\.net

When i run it i get :
user1@example.net user1.net not found
user2@example.net user1.net not found
user3@example.net user1.net not found
user1\@example\.net user1.net not found

When i try to match simple text it works but matching email ids doesn't.
What am i doing wrong here?

Please help me with this.

TIA,
SK

Boga Srinivas

2007-04-20, 6:58 pm

Hi kumar,

Try this.

bseenu@bseenu-dt:~/perl$ cat reg.pl
#! /usr/bin/perl
$id="user1\@example.net";
while(<> ) {
chomp($_);print "$_\t";
print "$id found\n" if /$id/;
print "$id not found\n" if ! /$id/;
}

bseenu@bseenu-dt:~/perl$ cat mail.txt
user1@example.net
user2@example.net
user3@example.net
bseenu@bseenu-dt:~/perl$ ./reg.pl < mail.txt
user1@example.net user1@example.net found
user2@example.net user1@example.net not found
user3@example.net user1@example.net not found


~Regards
-srini

Saravana Kumar wrote:
> Hi list,
>
> I am testing a regex with email ids. I have a list of ids that i want to
> match against a one more list of ids.
>
> I have this:
> #! /usr/bin/perl
> $id="user1@example.net";
> while(<> ) {
> chomp($_);print "$_\t";
> print "$id found\n" if /$id/;
> print "$id not found\n" if ! /$id/;
> }
>
> and a file /tmp/sampleids
> user1@example.net
> user2@example.net
> user3@example.net
> user1\@example\.net
>
> When i run it i get :
> user1@example.net user1.net not found
> user2@example.net user1.net not found
> user3@example.net user1.net not found
> user1\@example\.net user1.net not found
>
> When i try to match simple text it works but matching email ids doesn't.
> What am i doing wrong here?
>
> Please help me with this.
>
> TIA,
> SK
>
>
>


elsiddik

2007-04-20, 6:58 pm

On Apr 20, 7:26 pm, tuxku...@gmail.com (Saravana Kumar) wrote:
> Hi list,
>
> I am testing a regex with email ids. I have a list of ids that i want to
> match against a one more list of ids.
>
> I have this:
> #! /usr/bin/perl
> $id="u...@example.net";
> while(<> ) {
> chomp($_);print "$_\t";
> print "$id found\n" if /$id/;
> print "$id not found\n" if ! /$id/;
>
> }
>
> and a file /tmp/sampleids
> u...@example.net
> u...@example.net
> u...@example.net
> user1\@example\.net
>
> When i run it i get :
> u...@example.net user1.net not found
> u...@example.net user1.net not found
> u...@example.net user1.net not found
> user1\@example\.net user1.net not found
>
> When i try to match simple text it works but matching email ids doesn't.
> What am i doing wrong here?
>
> Please help me with this.
>
> TIA,
> SK




$id = "user1@example.com"; #you can't use this;
$id = "user1\@example.com" #good;
$id = 'user1@example.com' #also good;


zaher el siddik
http://elsiddik.blogspot.com/

Saravana Kumar

2007-04-20, 6:58 pm

Boga Srinivas wrote:

> Hi kumar,
>
> Try this.
>
> bseenu@bseenu-dt:~/perl$ cat reg.pl
> #! /usr/bin/perl
> $id="user1\@example.net";
> while(<> ) {
> chomp($_);print "$_\t";
> print "$id found\n" if /$id/;
> print "$id not found\n" if ! /$id/;
> }
>
> bseenu@bseenu-dt:~/perl$ cat mail.txt
> user1@example.net
> user2@example.net
> user3@example.net
> bseenu@bseenu-dt:~/perl$ ./reg.pl < mail.txt
> user1@example.net user1@example.net found
> user2@example.net user1@example.net not found
> user3@example.net user1@example.net not found
>
>
> ~Regards
> -srini


Yes. I have tried that. It works. My problem is that the $id that i am
matching will also be read from another file.

ie., a list of ids read one by one from a file and matched against another
file which has another list.

Thanks! for your time.

SK

>
> Saravana Kumar wrote:
>
>



Saravana Kumar

2007-04-21, 7:58 am

yitzle wrote:

> You can read one list into an array (@list) and then loop through the
> other file ($item) and grep the list for the item.
>
> for ($item = <> ) { # or foreach
> print "$item found" if ( grep $item, @list );
> }
>
> On 4/20/07, Saravana Kumar <tuxkumar@gmail.com> wrote:
>

Thanks to all who replied. Will try these out and post the results.

Regds,
SK

Saravana Kumar

2007-04-25, 7:58 am

Saravana Kumar wrote:

> yitzle wrote:
>
> Thanks to all who replied. Will try these out and post the results.
>
> Regds,
> SK


I tried various options but could not make it work. I was writing a perl
script to filter the mails.

The script will read directly from the mail program. Compare the from
addresses with contents in a file. If the id is present in the file then
the mail will be allowed; else denied.

First i regex the lines and store the from line in $from. Then i check if
the id(in $from) is in the acl file i have.

As you may know $from may have a String(fullname) with the email id or
simply the email id alone.

However i try it doesn't work. I can still give the ids directly in the if
condition(escaping @ & .). But i want to have the list of allowed ids in a
separate file so that the script need not be changed everytime we add new
ids.

ideas?

TIA,
SK

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com