http://www.perlmonks.org?node_id=80652


in reply to Fastest way to compare multiple variables?

if (($a == $b) && ($a == $c) && ($a == $d) ... ){ &do_something }
Update: There seems to be no way to solve this problem without listing each variable by name, since we do not know the names of the variables. So listing them and doing simple equality tests is as maintainable and efficient as other approaches.

A solution that one writes in baby Perl can be just as valid as any other, in the same way that the lyrics to Louie, Louie were as great as those of Dylan's Mr. Tambourine Man, and the Ramones (R.I.P. Joey) were as great as the Beatles.

Replies are listed 'Best First'.
Re: Re: Fastest way to compare multiple variables?
by Anonymous Monk on May 15, 2001 at 23:14 UTC
    I was about to do that, however the TIMTOWTDI / TIMTOWODI spirit hinted me to ask here.

    By the way, what's 'baby Perl'??
      I would define "baby Perl" as any Perl that one can write using only the constructs set forth in the first chapter of Merlyn (Randal L. Schwartz)'s estimable Lhama book "Learning Perl." Thus, one could use print, if, chomp, <STDIN>and even qw and tr but not grep, map, hashes, typeglobs, references and the flipflop operator.

      I say, if you know baby Perl, you can do almost anything, just as if you know a thousand words of French and the present tense conjugations of verbs you can get by in Paris.