On 2003.12.15, Tom Jackson <[EMAIL PROTECTED]> wrote:
> I'm trying to see if a value is an integer, using:
>
> if {[string is integer "${var}"]} {
>   do something
> }
>
> When var is the empty string it returns true, so I have to use:
>
> if {!("" eq "${var}) && ...
>
> Is this a bug, or expected behavior?

Expected behavior.  Read the docs for [string].  The short-hand for what
you want might look like this:

    if {[string is integer " $var"]} {
        ... do something ...
    }

Note the leading whitespace.  When $var is an empty string, this will
return 0.  Otherwise, if $var contains a valid integer, it'll return 1,
as [string is integer $str] ignores leading and trailing whitespace.
However, a non-empty string that contains no integer isn't an integer,
so the test does what you're expecting it to.

-- Dossy

--
Dossy Shiobara                       mail: [EMAIL PROTECTED]
Panoptic Computer Network             web: http://www.panoptic.com/
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of 
your email blank.

Reply via email to