Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Equivalent to Integer?

by cdherold (Monk)
on Feb 11, 2002 at 07:07 UTC ( [id://144588]=perlquestion: print w/replies, xml ) Need Help??

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
    =~

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://144588]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-24 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found