On Wed, Jun 27, 2001 at 01:15:05PM +0800, Exile wrote:
> >>>The problem is that when I compare the first and the second value: If
> >>>they're really equals, the program say they are'nt.

Notice "really equals".  I will be getting back to it.


> >>>Is ther a function to convert a value into an integer ?

 
> >You're comparing $a to $b using the regex operator.
> 
> Well, it's not all right, but half. Not $a to $b only, but $b to $a also.
> In case, I suppose everybody should know use "eq" to compair string...
> I just suggest another way, which not costing too much line.
> 
> As a CGI comparing habit, input a data twice is mostly in PASSWORD
> or E-MAIL, use double "=~" is visually help.

I can't really make this out.  As far as I can tell, you're trying to say
you need to compare $a to $b, as well as $b to $a.  Reversing the order of
the operands in an eq comparison gains nothing; reversing the order of
operands in a =~ comparison changes the meaning around entirely.

I don't understand the paragraph about CGI at all.

$a eq $b is not equivalent to $a =~ $b, or $b =~ $a, or even both.  What if
$a = "[f]" and $b = "f"?  Remember what I pointed out above, with him
wanting "really equals"?  Your comparison, $a =~ $b && $b =~ $a would state
$a and $b are equal.  Now, what if $a = "(foo"?  Suddenly, your comparison
causes a fatal error.


> > int is not for converting a string to an integer.
> 
> Anybody mension that "value" in terms of a "string"?  Couldn't it be a real
> number?

You're right, he didn't mention that the value was a string.  It could be a
real number.  The likelihood, however, that he would neglect to mention this
detail is pretty low.  Generally, "converting" from a float to an integer is
called "rounding" not "converting".


> In case, if a string is visually an interger number / real number ,
> there is no need to convert, right? $x = "10.5"; print ($x  - 10) will
> output as 0.5, right?

Yes, it will.  There are two conversions involved here; one from the string
"10.5" to the float 10.5, then from the number 0.5 to the string "0.5".  I'm
not sure what your point is, though.

 
> Unless returning an ASCII sort, I don't think there is any needs to convert
> a string to integer, right?

You can't subtract the number 10 from the string "10.5", one value has to be
converted to the other value's type, or they both have to be converted to
some common type.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to