[Rd] Perl question

David Brahm brahm@alum.mit.edu
Fri Feb 21 21:12:03 2003


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)