in reply to finding multiples of two values

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.

Replies are listed 'Best First'.
Re^2: finding multiples of two values
by JavaFan (Canon) on Sep 01, 2009 at 11:01 UTC
    1.2e40 is an integer as well, and does contain a dot in stringified form.
      The . - test is ok for beginners who are doing their first programming steps, but I agree that it isn't good for productional software.
      Besides the module way, I prefer the $X == int($X) - which also works for 1.2e40