Perl Programming Page 2 - Perl: Number Crunching |
As was the case in the Perl Text tutorials, some of this information I have skimmed over before. Feel free to skip over any subject you have already read about. Or if you want a refresher, keep reading. You should be familiar with some of these math operators. If not well, why don't you let me handle your finances for you? And remember...-$209 is more than $100. The first set of mathematical operators I will be forcing upon you are the +,-,*, %, and /. For those of you from the planet Alabama, those roughly translate to addition, subtraction, multiplication, modulo, and division. Here is some code showing each of them in use: #!/usr/bin/perl $myPay=2400; $britneyspay=232000; $kfedspay=800; $add=9+2; $subtract=9-2; print "Kevin Federline makes " . $kfedspay . " per month."; $combined= $britneyspay+$kfedspay; print "\nHe and Britney used to make " . $combined . " per month."; print "\nI am underpaid..."; print "Below is some simple math:\n\n"; print "\n9+2 equals: " . $add; print "\n9-2 equals: " . $subtract; print "\n9*2 equals: " . 9*2; print "\n9/2 equals: " . 9/2; print "\n9%2 equals: " . 9%2; This magnanimous code gives us the following result: Kevin Federline makes 800 per month He and Britney used to make 232800 per month I am underpaid...Below is some simple math: 9+2 equals: 11 9-2 equals: 7 9*2 equals: 18 9/2 equals: 4.5 9%2 equals: 1 As you can see, being talentless pays well. You might also be staring at one of those equations and scratching your head (if you are Britney, you may have hired someone to scratch it for you; and it probably itches a lot now that you have shaved it). And that would be my little buddy the modulo (9%2 equals: 1). Modulo, for those who don't know, returns the remainder of a division. For instance, 9/2 equals 4 with a remainder of 1. So the result is...1. Magic, I know.
blog comments powered by Disqus |
|
|
|
|
|
|
|