in reply to Re: var comparison
in thread var comparison
There were no hidden intentions. My question was simply the product of my poor knowledge of Perl :^)
Although it's true that shorter doesn't always mean more efficient, it's also true that when you start with a language you tend to use long and complicated expressions to accomplish tasks that, once you have a little (or no so little) more knowledge, you realize that could have been done in a much shorter (and usually clearer) way.
I was just wondering if this was the case, so the expression:
$var eq 'foo' || $var eq 'bar'could be translated to something like:
$var eq (foo|bar) (which, of course, does not work)or similar, the same way the defined-or operator helps to turn $x = $x // 5 into $x //= 5, for instance.
(I understand that the implications of doing $var eq (foo|bar) would probably be more complex).
Consider also that the case I proposed had only two options to compare, so the first version is OK, but with more options a shorter manner would be appreciated. Since that seems not possible, a function would be the best solution as suggested by MidLifeXis.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: var comparison
by Marshall (Canon) on Sep 09, 2012 at 19:14 UTC | |
|
Re^3: var comparison
by Anonymous Monk on Sep 08, 2012 at 08:57 UTC | |
by nemesisgus (Acolyte) on Sep 08, 2012 at 18:32 UTC | |
by LanX (Saint) on Sep 08, 2012 at 18:42 UTC | |
by nemesisgus (Acolyte) on Sep 09, 2012 at 02:03 UTC | |
by Anonymous Monk on Sep 09, 2012 at 08:47 UTC | |
|