in reply to Re: howto make a very long IF statment shorter
in thread howto make a very long IF statment shorter
No good. "b matches a" doesn't necessarily follow from "a matches b". In fact, when it does, you should be using eq, not a regexp.
outputsuse strict; use warnings; my $var_a = ''; my $var_b = 'abc'; my $var_c = ''; if ( $var_a =~ /abcdefgh/ || $var_b =~ /abcdefgh/ || $var_c =~ /abcdefgh/ ) { print("orig: true\n"); } else { print("orig: false\n"); } if ( q{abcdefgh} =~ /(?:$var_a|$var_b|$var_c)/ ) { print("johngg: true\n"); } else { print("johngg: false\n"); }
orig: false johngg: true
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: howto make a very long IF statment shorter
by johngg (Canon) on Jul 05, 2006 at 17:10 UTC | |
by ikegami (Patriarch) on Jul 11, 2006 at 16:50 UTC | |
by johngg (Canon) on Jul 11, 2006 at 20:28 UTC |