Perl
  Home arrow Perl arrow Perl: Number Crunching
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Perl: Number Crunching
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 3
    2008-08-05

    Table of Contents:
  • Perl: Number Crunching
  • Smooth Operator
  • Operator Precedence
  • The Positive and the Negative
  • Proselytizing Numbers into Holy Strings!

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Perl: Number Crunching


    (Page 1 of 5 )

    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.

    The year was...well I don't know exactly what year it was. But there stood Pythagoras of Samos, the great Greek magician and founder of the religion, Pythagoreanism, which is almost as wacky as Scientology, except L. Ron Hubbard didn't name it Hubbardism. You probably know this Greek bad-ass as the guy who made you fail all your math classes when you couldn't tell your professor what the Pythagorean Theorem was.

    At any rate, there he stands, and next to him is Hipassus of Metapontum, who takes a sip of his Mountainus Dewus and says, "Hey...I discovered this thing called irrational numbers." He then went on to explain them to Pyth, who, well, got really Pythed off, exclaimed he would not accept the existence of irrational numbers, and sentenced Hippasus to death by drowning.

    So what's my point in telling you all that? Numbers are best left to those that know them well, and hardly anyone knows them better than computers. Sometimes this can make working with math in programs difficult, because some are real finicky about how you do your equations. But not our boy Perl (who by the way, has a very effeminate name). Perl makes math simple. Whereas in some languages you have to differentiate between the data types of the math you are performing, in Perl there is no need. And while that might not make sense right this minute, it will very shortly.

    Enough rambling. As Morpheus says to Neo in the Matrix...Damn these are some good biscuits.

    These Numbers Be Keeping It Real

    In the world of computers there are two types of numbers: integers and floating-point numbers (also known as real numbers, hence my witty headline). Floating point numbers are decimals, while integers are whole numbers.

    In the majority of programming languages, you need to differentiate between floating point and integer numbers. Perl, however, is a math magician. When you type in the number 49, it says, "Hey...that's an integer." If you type in 2.7, then again Perl uses its massive brain to explain to the computer that that number is a floating point.

    Here is some sample code showing how to declare integer and floating point variables:


    #!/usr/bin/perl

    $real=7.11;

    $regetni=8;

    print "This numba be keepsin it real: " . $real;

    print "\n This is an integer: " . $regetni;

    As you can see, you do so the same way. Here is the result:

      This numba be keepsin it real: 7.11

      This is an integer: 8

    More Perl Articles
    More By James Payne


       · 5 + 9 * 2 = 235 + (9 * 2) also = 23as it does in Perl and just about any other...
       · Hey thanks for the comments. I did, and always do, test the code, and the math for...
     

       

    PERL ARTICLES

    - More Templating Tools for Perl
    - Site Layout with Perl Templating Tools
    - Build a Perl RSS Aggregator with Templating ...
    - Looping, Security, and Templating Tools
    - Perl: Bon Voyage Lists and Hashes
    - Templating Tools
    - Perl: Number Crunching
    - Perl Debuggers in Detail
    - Debugging Perl
    - Perl: More on Lists and Hashes
    - Perl: Dimensional Lists
    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT