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 <[EMAIL PROTECTED]> wrote:
Boga Srinivas wrote:

> Hi kumar,
>
> Try this.
>
> [EMAIL PROTECTED]:~/perl$ cat reg.pl
> #! /usr/bin/perl
> $id="[EMAIL PROTECTED]";
> while(<>) {
> chomp($_);print "$_\t";
> print "$id found\n" if  /$id/;
> print "$id not found\n" if ! /$id/;
> }
>
> [EMAIL PROTECTED]:~/perl$ cat mail.txt
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]:~/perl$ ./reg.pl < mail.txt
> [EMAIL PROTECTED]       [EMAIL PROTECTED] found
> [EMAIL PROTECTED]       [EMAIL PROTECTED] not found
> [EMAIL PROTECTED]       [EMAIL PROTECTED] 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:
>> 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="[EMAIL PROTECTED]";
>> while(<>) {
>> chomp($_);print "$_\t";
>> print "$id found\n" if  /$id/;
>> print "$id not found\n" if ! /$id/;
>> }
>>
>> and a file /tmp/sampleids
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>> [EMAIL PROTECTED]
>>
>> When i run it i get :
>> [EMAIL PROTECTED]       user1.net not found
>> [EMAIL PROTECTED]       user1.net not found
>> [EMAIL PROTECTED]       user1.net not found
>> [EMAIL PROTECTED]     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

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to