[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: problem in GNU Awk 3.1.3 - comparison does not work
From: |
Aharon Robbins |
Subject: |
Re: problem in GNU Awk 3.1.3 - comparison does not work |
Date: |
Sun, 11 Apr 2004 10:25:29 +0300 |
Greetings.
I suggest you read the gawk documentation on comparisons. The values
in this case are treated as strings for comparison, thus "4" is greater
than "12".
You can add the line
lmonth = lmonth + 0
after the
lmonth = sprintf("%d", sa[2])
or change it to
lmonth = sprintf("%d", sa[2]) + 0 # force numeric
to force lmonth to be a numeric value.
Arnold
> Date: Sun, 11 Apr 2004 01:27:23 +0200 (MEST)
> From: "Thomas Strasser" <address@hidden>
> To: address@hidden, address@hidden
> Subject: problem in GNU Awk 3.1.3 - comparison does not work
>
> Dear Sir or Madam!
>
> The following program has a problem in the comparsion:
>
> #!/bin/bash
> # using 'GNU Awk 3.1.3' from cygwin-package
> echo " Samstag, 10.4.2004" | gawk '{
> }
> function myfunc(sdate)
> {
> split(sdate, sa, "\\.");
> lmonth = sprintf("%d", sa[2]); # get 4
> printf("+++lmonth is \"%d\";\n", lmonth); # => output: +++lmonth is "4";
> if ( lmonth > 12 ) # BUG: this should be false, but is true!!!
> {
> printf("+++month:=%d>12!\n", lmonth); # => output: +++month:=4>12!
> return 0;
> }
> else
> printf("+++month:ok;\n");
> }
> { myfunc($2);
> }'
>
> If there are any information you need, feel free to write me an answer.
>
> Yours sincerely
> Thomas Strasser
>
> --
> NEU : GMX Internet.FreeDSL
> Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/info
- Re: problem in GNU Awk 3.1.3 - comparison does not work,
Aharon Robbins <=