$Bill Luebkert wrote

>Paul Rogers wrote:
>> What's the simplest/shortest way to write an IF statement given that I'm 
>> looking for the variable to be one of 5 possible choices?
>> 
>> E.g.,
>> 
>> if ($x eq 'a' or $x eq 'b' or $x eq 'c or $x eq 'd' or $x eq 'e') {
>>     blah
>> }
>> 
>> I guess what I'm asking for is if there is a way to simplify/shorten this

>> structure?
>
>You could use a RE, but it may be slower :
>
>if ($x =~ /^[abcde]$/) {
>       code
>
>if the characters were words :
>
>if ($x =~ /^(word1|word2|word3|word4)$/) {
>       code

I always thought that RE was faster. In light of this, which of the
following is better

        if ( $test =~ /^Start of text/so  ) {

or

        if ( substr ( $text , 0 , 13 ) eq 'Start of text' ) {

Thanks
Bill Conrad
                            
             
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to