cdherold has asked for the wisdom of the Perl Monks concerning the following question:

Yup, I'm back already.

I'm trying to do the following:

if ( $base/3 !== integer){then do this;}
but i don't know what to use for the integer variable? I only want it the program to continue if $base/3 is NOT an integer. If i'm being an idiot please let me know. this seems like it should be a very easy one.

thanks again,

cdherold

Replies are listed 'Best First'.
Re: Equivalent to Integer?
by grep (Monsignor) on Feb 11, 2002 at 07:13 UTC
    how 'bout int, the integer function.

    if ( $base/3 != int($base/3)){then do this;}

    BTW 'perldoc -f int' would have told you.
    perldoc is your friend

    UPDATE:This is also a FAQ 'perldoc -q integer' though I like my solution better than the regexps

    grep
    grep> chown linux:users /world
Re: Equivalent to Integer?
by Biker (Priest) on Feb 11, 2002 at 07:15 UTC

    if($base/3 != $my_integer)
    Or was that '!==' just a typo? And was the integer without a $ a typo as well?

    If so, you may want to look into using the modulus operator '%'.


    Everything will go worng!

Re: Equivalent to Integer?
by Zaxo (Archbishop) on Feb 11, 2002 at 07:48 UTC
    die if $base % 3;

    Update: Oops, dup of Biker's idea.

    After Compline,
    Zaxo

Re: Equivalent to Integer?
by screamingeagle (Curate) on Feb 11, 2002 at 07:18 UTC
    quoting from PerlFaq4, here are various ways to check if a scalar variable is a number/whole/integer/float :
    if (/\D/) { print "has nondigits\n" } if (/^\d+$/) { print "is a whole number\n" } if (/^-?\d+$/) { print "is an integer\n" } if (/^[+-]?\d+$/) { print "is a +/- integer\n" } if (/^-?\d+\.?\d*$/) { print "is a real number\n" } if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { print "is a decimal number" } if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { print "a C float" }
    (Take your pick)... and if u want to use a negated regular expression, use the
    !~
    syntax instead of the
    =~