PDA

View Full Version : integers comparing as string


systemofadown
07-28-2004, 09:07 PM
hello. i have a file on my webserver that is modified every time a certain file is accessed with the data and time of the access. every script that in some way modifies that specific file updates it when it is run. now im working on the verification sub that checks whether the file was modified while the user was on a page that allows modification. basically when a page is created that links to the delete script, it is given a hidden input type that contains the date and time, and when the script is run, it compares that hidden value to the file value. for some reason, the code seems to be checking the values as strings rather than integers. the code is as follows:

($year,$mon,$day,$hour,$min,$sec)=split(/-/,$FORM{'mod'});
($myear,$mmon,$mday,$mhour,$mmin,$msec)=split(/-/,$mod);#$mod is read from file
if (($myear=>$year) and ($mmon=>$mon) and ($mday=>$day) and ($mhour=>$hour) and ($mmin=>$min) and ($msec=>$sec)) {
#Raise Error: File was modified
}

i replaced the actual code since it is not necessary to show it. the problem im having is that regardless of the time it seems to raise the error anyways. im am assuming that it is performing a string length comparison vs. comparing their values which is why it still fires when it shouldnt. if anyone knows how i can fix this problem please let me know.

systemofadown
07-28-2004, 10:47 PM
aaaaargh, i figured out the stupid problem i was having. it turns out it wasnt that they were being compared as string lengths, it turns out that the coding line $msec=>$sec didnt get interpreted as greater than or equal to. i guess perhaps that is not the correct cgi notation. neways i replaced it with .... and(($msec>$sec) or ($msec==$sec)) and it seems to have solved the problem.
does anyone kno what the problem is with =>?

Calilo
07-29-2004, 12:34 AM
The thing is you were typing them backwards, here is a list for numerical comparissons.

==, !=, <, >, <=, >=

i think you allready know what each means but here it goes.

== equal to.
!= not equal to.
< smaller than.
>bigger than.
<= smaller or equal to.
>= bigger or equal to.

that is why it was not working, you should use them like this, in order to clean up your code, it is better than to use AND OR, many times.

Calilo

Grant Palin
07-29-2004, 01:33 AM
If I recall correctly, those operators are for comparing numbers.

To compare strings, you want to use eq and neq (between the two strings being compared).