> This code doesn't need to be fixed. For style, I would remove the > inner parens (unnecessary) and change the function calls to > do_something() instead of the (old-style) &do_something.
Is changing the function calls just a matter of style, or is there a more important reason to do it? > But your handling of the condition is fine. If you want to make it more > readable, you could format it as: > > if ($something eq 'string0' > || $something eq 'string1' > || $something =~ /string2/) { Excellent. I had done this in a past case last year, but couldn't get it to work properly. Perhaps I was making another unrelated mistake and failed to see it. Anyway, this is an excellent alternative. Also is there any harm in combining the first too tests into one as below... if ($something eq ('string0'|'string1') || $something =~ /string2/) { ...or is that method flawed? If yes .. in what way? > > if ($something eq ('string0' || 'string1' || =~ /string2/)) { > > &do_something; > > } else { > > &do_somthing_else; > > } > > It doesn't work, because it's not equivalent. It also contains > a syntax error. I realise it was silly, it was just a 'what if' scenerio to give you an idea of roughly what I was after in the way of brevity. > > my $test_ok; > > $test_ok = 1 if ($something eq 'string0'); > > $test_ok = 1 if ($something eq 'string1'); > > $test_ok = 1 if ($something =~ /string2/); > > if ($test_ok) { > > &do_something; > > } else { > > &do_somthing_else; > > } > > How is this better? It's actually slower, because every test is evaluated. I originally arrived at this method when testing for invalid characters and character combinations in an email address. Because of a few exceptions I couldn't simply test for non-alpha-numerics and be done with it. I had to test for each char and illegal combo explicitely. I did something like above to make the 30 or so tests easier to visually keep track of. I actually put 3 or 4 tests in each if statement, but had several of them one line after another. That way I could simply evaluate if a certain value exists, and if not, there are no errors. If I had a problem with the results I could just comment out one line at a time until I found the source. I'm mostly self taught and learning by trial and error + perldoc.com ;) This is also my first language apart from HTML. > In your original formulation, the entire expression would become true > as soon as the first sub-expression was true. That's the idea. > Also, this one needs an intermediate variable, and is harder to > read. True. Like I said, it was a kluge. :) > Your original code is the proper way to do it. All the other solutions > proffered are inferior, IMO. > > if($something =~ /^(string0|string1|string2)$/) > > is not equivalent to your original condition. It's also likely to be > inefficient. In what way would you consider it inefficient? How about this... if ($something =~ /(^string0$|^string1$|string2)/) { I'm still learning and ironing out alot of my understanding of proper syntax (especially since I've canabalised alot of Perl4 stuff until recently), so I appreciate your indulgence. You've already helped me immensely. =================== Shaun Fryer =================== London Webmasters http://LWEB.NET PH: 519-858-9660 FX: 519-858-9024 =================== -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]