On Fri, Dec 20, 2002 at 05:00:04PM +0530, Ramprasad wrote:

> hello all
> 
> Assume the foll
> 
> $string='mail.com';
> @array=qw(mail.com one.mail.com two.mail.com mail.com/one mail1.com);
> 
> @match = grep{..}@array;
> 
> I want to match all  that *contain* $string but is not equal to $string
> 
> so I came up with
> 
> @match = grep{/^$string.+/ || /.+$string$/} @array;
> 
> is there any better way

I don't know about better, but why not code it exactly as you describe
it?

  @match = grep { index($_, $string) >= 0 and $_ ne $string } @array;

This has the advantage of not needing to escape the meta characters so
you won't get false positives.  Add xmailxcom to @array.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to