From brahm@alum.mit.edu  Fri Feb 21 21:12:03 2003
From: brahm@alum.mit.edu (David Brahm)
Date: Fri Feb 21 21:12:03 2003
Subject: [Rd] Perl question
References: <e30d5voq9g2pb71vqqeqk1ev05jb9os5i0@4ax.com>
Message-ID: <15958.34766.979274.188826@gargle.gargle.HOWL>

Duncan Murdoch wrote:
> What is a good Perl equivalent of the R statement
>  if ( s %in% c('string1', 'string2', 'string3') )  ...

Dirk Eddelbuettel <edd@debian.org> replied:
  if (s =~ m/(string1|string2|string3)/o) {  ...
(I think Duncan and Dirk both meant "$s" instead of "s".)

I'd also suggest:
  @mylist = ("string1","string2","string3");
  if (grep /^$s$/, @mylist) {print "yes\n"}

(after all, There's More Than One Way To Do It.)
-- 
                              -- David Brahm (brahm@alum.mit.edu)



[Rd] Perl question
David Brahm