First, think about how to answer your question:
Is 48 a multiple of 12?
How do you do this (without a computer)? You divide 48 by 12...
48 / 12 = 4
Okay, "4" has no decimals (e.g. no "." or "," depending on your locale preference), so the answer is yes.

Now let's do this in Perl:

# First make the program know the two numbers: $Number1 = 48; $Number2 = 12; # Now divide the numbers: $Result = $Number1 / $Number2; # ...and look if we got a decimal:
Let's stop for a moment. There are many ways to do the check, here are some of them:
# Using your sub is_integer_string($Result) # Look for a . $Result =~ /\./; # Check if the number is the same as its integer part: $Result == int($Result)
I prefer the last one. It compares the number to the integer part (e.g. everything before the . without rounding) and if they're the same - everything is fine.
Of cause, you need to add a
if (condition) { print "Yes"; } else { print "No"; }

Regarding your subroutine... I think it won't work as you expect: Leaving the \s* alone, you're matching a + sign followed by zero or one - sign followed by numbers. +3 matches, but the string representation of a number doesn't include a leading + in Perl. Better to put [] around the \+ and \- (and keep the ?). This will match either a -, a + or nothing before the number.
Perl could do a good part of the job for you if you want to match using a regexp:

sub is_integer_string { my $N = $_[0] + 0; return $N =~ /^\-?\d+$/; }
Any mathematical operation will see the input variable as a number (including everything Perl accepts here). Adding 0 means: Don't change my number at all, but force it to be a Perl number with a known syntax which could be matched easily.

Update: Just noticed JavaFan's comment and he's right: modulo is the quickest way to do it, but all the others shown here also work.


In reply to Re: finding multiples of two values by Sewi
in thread finding multiples of two values by urnumdei

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.