Luke Palmer wrote:

>>> From: "Joe Gottman" <[EMAIL PROTECTED]>
>>> Date: Fri, 3 Jan 2003 22:25:16 -0500
>>> 
>>> "JG" == Joe Gottman <[EMAIL PROTECTED]> writes:
>>> 
>>>   JG>   Speaking of which, is there a run-time test to check if a variable
>>>   JG>   is of
>>>   JG>  integral type?  Something like
>>>   JG>  print "date" if ($var is int) && (1 <= $var <= 31);
>>> 
>>> the old standby is:
>>> 
>>> int( $var ) == $var
>>
>>    I'm not sure if this works.
>>
>> my $var = "0";  # Notice the quotation marks
>> print "is integer" if (int($var) == $var);
>>
>> In the above case int($var) == $var returns true when I would want it to
>> return false.

Why?  It returns true in perl5; 0 certainly is an integer value.

>     print "date" if $var.isa(int);
>     print "date" if isa $var: int;
>     print "date" if $var ~~ int;
> 
> Those should all work.  IMO the first reads the best.  That will also
> work for C<Int>s, as C<Int> is a subclass of C<int> (I think).

These only determine if $var is of type int or Int.  However:

my $var = 0;
# or my $var = "0";
# or my int $var = 0;
# or my num $var = 0;

# all 4 cases should print "is integer"
print "is integer" if int $var == $var;

This should work as a more generic method to test Integer *value*,
rather than type, which IMHO is more useful (and more commonly wanted).

This message was sent using the Webmail System hosted by OARDC Computing Services  -- 
http://webmail.oardc.ohio-state.edu:8080

Reply via email to