Re: simple if?

2005-03-05 Thread Chris Wagner
That was a really good test. PS, I really like ur sig. ;) -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede males" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: ht

Re: simple if?

2005-03-05 Thread Roger Keane
Chris Wagner wrote: I figured I should try the benchmark against ur original question. use Benchmark qw(cmpthese); $now = time; my $t = "bob"; my $count = 500; cmpthese ($count, { 'OR' => sub { 1 if ($t eq "joe" or $t eq "bar" or $t eq "foo" or $t eq "bob" ); },

Re: simple if?

2005-03-03 Thread Chris Wagner
I figured I should try the benchmark against ur original question. use Benchmark qw(cmpthese); $now = time; my $t = "bob"; my $count = 500; cmpthese ($count, { 'OR' => sub { 1 if ($t eq "joe" or $t eq "bar" or $t eq "foo" or $t eq "bob" ); }, 'RE' => sub {

Re: simple if?

2005-03-03 Thread Chris Wagner
Yeah I was suspecting u were on 64 bit. Maybe the regex engine just isn't optimized for 64 bit qwords. If it's just running 32 bit words then 50% of ur XOR capacity is wasted. But then u would think that u'ld beat me on pure clock speed. I seriously doubt that a Celeron is "better" in any way t

Re: simple if?

2005-03-03 Thread $Bill Luebkert
Chris Wagner wrote: > At 07:33 AM 3/3/05 -0800, $Bill Luebkert wrote: > >>I tried 3 different lengths of $text and substr is the clear winner. >>Longest string: >> Rate RE substr >>RE 916926/s -- -70% >>substr 3076923/s 236% -- > > > > That's very interesting, I

Re: simple if?

2005-03-03 Thread Chris Wagner
At 07:33 AM 3/3/05 -0800, $Bill Luebkert wrote: >I tried 3 different lengths of $text and substr is the clear winner. >Longest string: >Rate RE substr >RE 916926/s -- -70% >substr 3076923/s 236% -- That's very interesting, I ran ur exact code (except for $x++) and

RE: simple if?

2005-03-03 Thread Conrad, Bill (ThomasTech)
$Bill Luebkert wrote >What are you lazy ? :) Try benchmarking it yourself. > >use Benchmark qw(cmpthese); Its not a question of being Lazy. I asked the question because I wanted the opinion of those who know more then I do. I did not know of 'use Benchmark'. Thanks for the info. Bill C

RE: simple if?

2005-03-03 Thread Chris Wagner
At 10:13 AM 3/3/05 -0500, Conrad, Bill (ThomasTech) wrote: >I always thought that RE was faster. In light of this, which of the >following is better > > if ( $test =~ /^Start of text/so ) { > if ( substr ( $text , 0 , 13 ) eq 'Start of text' ) { In that case they'ld probably be about

Re: simple if?

2005-03-03 Thread $Bill Luebkert
Conrad, Bill (ThomasTech) wrote: > $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

RE: simple if?

2005-03-03 Thread Conrad, Bill (ThomasTech)
$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

Re: simple if?

2005-03-03 Thread Hugh Loebner
How about using a hash?: use strict ; my $x; my %wanted ; foreach (qw( word1 word2 whatever this that the-other) ){ $wanted{$_}= 1; } ; $x = 'the-other' ; if( $wanted{$x} ){ print "found $x\n" ; } else{ print "can't find $x\n" ; } ; $x = 'no-go' ; if( $wanted{$x} ){

Re: simple if?

2005-03-02 Thread Chris Wagner
I think ur first way was the best way. It all depends on what the comparison is. If it's simple, use or's, but if it gets long and complicated then it's worth it to use regex. Better to do one or two XOR's than load up the regex engine. But of course u won't notice any difference unless ur doin

Re: simple if?

2005-03-02 Thread $Bill Luebkert
Fowler, Terry R wrote: > Paul: > >>>if ($x eq 'a' or $x eq 'b' or $x eq 'c or $x eq 'd' or $x eq 'e') { > > > $Bill: > >>if ($x =~ /^[abcde]$/) { > > > Oh pooh. I almost got to answer a question but I hesitated to hit > the Send button. I was going to suggest /[a-e]/; would that be > wrong

Re: simple if?

2005-03-02 Thread Paul Rogers
- Original Message - From: "$Bill Luebkert" <[EMAIL PROTECTED]> if ($x =~ /^(word1|word2|word3|word4)$/) { Aha! Yes...this will do it for sure. Thanks :-) Paul --- ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To un

RE: simple if?

2005-03-02 Thread Fowler, Terry R
Paul: >> if ($x eq 'a' or $x eq 'b' or $x eq 'c or $x eq 'd' or $x eq 'e') { $Bill: > if ($x =~ /^[abcde]$/) { Oh pooh. I almost got to answer a question but I hesitated to hit the Send button. I was going to suggest /[a-e]/; would that be wrong if I knew I was looking for abcde? Terry Fowler

Re: simple if?

2005-03-02 Thread $Bill Luebkert
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

simple if?

2005-03-02 Thread Paul Rogers
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 structu