From rpeng@stat.ucla.edu  Fri Feb 21 21:16:03 2003
From: rpeng@stat.ucla.edu (Roger Peng)
Date: Fri Feb 21 21:16:03 2003
Subject: [Rd] Perl question
In-Reply-To: <e30d5voq9g2pb71vqqeqk1ev05jb9os5i0@4ax.com>
Message-ID: <Pine.GSO.4.10.10302211210350.7640-100000@quetelet.stat.ucla.edu>

I sometimes hack something with a hash:

%keywords = ( "string1" => 1, "string2" => 1, "string3" => 1 )

and then do something like:

exists($keywords{$mystring}) 

which should be true if $mystring is one of "string1", "string2", or
"string3".

-roger
_______________________________
UCLA Department of Statistics
rpeng@stat.ucla.edu
http://www.stat.ucla.edu/~rpeng

On Fri, 21 Feb 2003, Duncan Murdoch wrote:

> I'm working on the installer code, but I don't know Perl well enough.
> What is a good Perl equivalent of the R statement
> 
>  if ( s %in% c('string1', 'string2', 'string3') )  ...
> 
> I can do it with 
> 
>  if (s == "string1" || s == "string2" || s == "string3")  ...
> 
> but I've got a feeling there's a better way to do it using associative
> arrays.  
> 
> The real example will have about a dozen fixed strings that I want to
> search a few thousand times.
> 
> Duncan Murdoch
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Perl question
Roger Peng