On 12 Mar, 15:28, Janis <janis_papanag...@[EMAIL PROTECTED]
> wrote:
> On 12 Mrz., 15:15, Luuk <L...@[EMAIL PROTECTED]
> wrote:
>
>
>
>
>
> > di98mase schreef:
>
> > > Hi
>
> > > I have a file with numbers in it. My program reads the values and
> > > compare them and depending on the value I increment a counter. what
I
> > > have seen is that the evaluation fails. This is an extract of my
> > > numbers:
>
> > > 7
> > > 7
> > > 7
> > > 34
> > > 92
> > > 111
> > > 294
> > > 121
> > > 142
>
> > > This is parts of my program that checks the value (ms) read from the
> > > file and increments the counters
>
> > > =A0 =A0 =A0 if( ms =3D=3D 18) t18++;
> > > =A0 =A0 =A0 if( ms =3D=3D 19) t19++;
> > > =A0 =A0 =A0 if( ms >=3D 20 && ms < 30)
> > > =A0 =A0 =A0 {
> > > =A0 =A0 =A0 =A0 =A0print ms;
> > > =A0 =A0 =A0 =A0 =A0t20++;
> > > =A0 =A0 =A0 }
> > > =A0 =A0 =A0 if( ms >=3D 30 && ms < 40) t30++;
> > > =A0 =A0 =A0 if( ms >=3D 40 && ms < 50) t40++;
> > > =A0 =A0 =A0 if( ms >=3D 50 && ms < 60) t50++;
> > > =A0 =A0 =A0 if( ms >=3D 60 && ms < 70) t60++;
>
> > > As you can see I dont have any numbers between 20 and 30 but I still
> > > get an increment for the t20 counter. When I print the value it is
> > > "294". Why do I have this behaviour?
>
> > its compared alphanumeric
>
> The interesting question is; Why?
>
> And the answer might most likely be that 'ms' had been converted
> to a string somewhere in an unquoted part of his program (i.e.
> the opposite of the conversion you propose below). So if there's
> some code like
>
> =A0 =A0{ =A0ms =3D $1 ""
> =A0 =A0 =A0 ...
> =A0 =A0 =A0 if( ms =3D=3D 18) t18++;
> =A0 =A0 =A0 if( ms =3D=3D 19) t19++;
> =A0 =A0 =A0 if( ms >=3D 20 && ms < 30)
> =A0 =A0 =A0 ...
> =A0 =A0}
>
> It might be a more appropriateto fix the original number-to-string
> conversion.
>
> Janis
>
>
>
>
>
> > this will work:
> > if( 0+ms >=3D 20 && 0+ms < 30)
>
> > --
> > Luuk- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -- D=F6lj citerad text -
>
> - Visa citerad text -- D=F6lj citerad text -
>
> - Visa citerad text -
Hi all,
this is the missing part that converts from a string to an int that
was not shown in the previous post:
# Try to find out the transaction times from the logs that looks like:
# /I/TR End, Time:82433(89) Stat:0/0016e0dch:(
/TR End, / {
match($3,"Time:")
usecStart =3D RSTART + RLENGTH
match($3,"[(]")
usecEnd =3D RSTART
usecLen =3D usecEnd - usecStart
us =3D substr($3 , usecStart, usecLen)
# Make sure that all found the matching pattern
if (usecStart !=3D -1 && usecEnd !=3D -1 && usecLen !=3D -1)
{
# Convert to ms and truncate decimals
temp =3D us/1000;
ms =3D sprintf ("%d", temp)
if( ms =3D=3D 1) t1++;
if( ms =3D=3D 2) t2++;
if( ms =3D=3D 3) t3++;
if( ms =3D=3D 4) t4++;
if( ms =3D=3D 5) t5++;
etc
etc
I thougth that the sprintf would convert the string to a number, or?


|