Home arrow Perl Programming arrow Page 2 - Perl: Number Crunching

Smooth Operator - Perl

In this tutorial we will look at working with numbers in Perl. We'll cover the basics, such as integers and floating points, and end with the more advanced topics, like converting strings to numbers. With Perl you don't need to be a math genius. These simple tips can help you be a virtual Einstein.

  1. Perl: Number Crunching
  2. Smooth Operator
  3. Operator Precedence
  4. The Positive and the Negative
  5. Proselytizing Numbers into Holy Strings!
By: James Payne
Rating: starstarstarstarstar / 6
August 05, 2008

print this article



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:







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.

>>> More Perl Programming Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates


Dev Shed Tutorial Topics: