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

For the life of me, I cannot figure out how to divide a number by a number.

I thought I once knew, but I guess not.

Here is what I'm trying to do:
my $im1 = 30; my $cl2 = 20; my $answer = ($im1/$cl2);

How do I divide the 30 string by the 20 string?

thx,
Richard

Replies are listed 'Best First'.
Re: Divide by...
by dws (Chancellor) on Feb 15, 2003 at 02:19 UTC
    For the life of me, I cannot figure out how to divide a number by a number.
    my $im1 = 30; my $cl2 = 20; my $answer = ($im1/$cl2); print $answer;
    prints
    1.5
    Where, exactly, is the problem?

Re: Divide by...
by pfaut (Priest) on Feb 15, 2003 at 02:20 UTC

    What makes you think it didn't work? Where's the rest of your code?

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: Divide by...
by powerhouse (Friar) on Feb 15, 2003 at 02:49 UTC
    Sorry. I was getting an error everytime. It said I could not divide by 0. What happened, is I'm getting my values from a MySQL database, then counting the entries, and putting them into an HTML table. I'm dividing two of them to get the ratio, but some of the values where 0, so I had to add a unless the string is equal to 0. Then it worked.

    I thought I was doing it wrong, but I guess It was just that. Thank you though!!!

    BTW, Last time I asked a MySQL syntax question here I got downvoted, so, can you please tell me where a good place to ask is, I just joined the MySQL list, and I asked a question there this morning, and it still has not been answered, nor have I seen it come across my list email account. So Maybe there is a better place to ask?

    thx,
    Richard

      You could try first asking your questions in the chatterbox. A lot of questions that aren't related to perl get answered there. If there aren't any monks around that can answer your questions, someone might be able to point you in the right direction to a better place to ask. If your question would be better asked in a SoPW post, the people in the chatterbox will tell you that.

      --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: Divide by...
by Anonymous Monk on Feb 15, 2003 at 02:20 UTC

    What makes you think you don't know?

    $ perl my $im1 = 30; my $cl2 = 20; my $answer = ($im1/$cl2); print $answer ^D 1.5