Home > Archive > PERL Beginners > March 2005 > Re: [PBML] Finding index of given value in an array
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PBML] Finding index of given value in an array
|
|
| Offer Kaye 2005-03-30, 3:56 pm |
| On 29 Mar 2005 10:19:09 -0800, Randal L. Schwartz wrote:
>
> No, you should change it only when appropriate. "35.0" is not eq to "35",
> and yet they are numerically equal.
>
Dratz, foiled again! ;-)
> I hope you don't write the rest of your code like that. :(
>
In this specific case I had no way to know what the OP has as data,
numbers or strings, so I assumed the general case. If you have strings
and use the "==" operator, you get warnings, no way around that (I'm
assuming "use warnings;" in effect). No only that, use also get a
wrong answer (e.g. "a" == "b" is TRUE).
If you use "eq" and are trying to find "35.0" when the string "35" is
the one you really want, and get a "no match" result, I would say that
is the correct behaviour and the "no match" result is actually
correct, or at least less wrong, since if you have both strings and
numbers I see no way to use "==" for comparison without getting false
results. Am I right?
Regards,
--
Offer Kaye
| |
| Randal L. Schwartz 2005-03-30, 3:56 pm |
| >>>>> "Offer" == Offer Kaye <offer.kaye@gmail.com> writes:
Offer> In this specific case I had no way to know what the OP has as data,
Offer> numbers or strings, so I assumed the general case.
No, the point here is that THERE IS NO GENERAL CASE.
You either want numeric comparisons, or string comparisons. You can't
use string comparisons for "both".
That's why I keep correcting you.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
|
|
|
|
|