Perl
  Home arrow Perl arrow Page 3 - Perl: Number Crunching
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PERL

Perl: Number Crunching
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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 - Operator Precedence
    ( Page 3 of 5 )

    In Perl, and I believe pretty much most of the languages out there, you give precedence to an equation by encapsulating it in parentheses. Consider the following:

      5 + 9 * 2 = 28

      5 + (9 * 2) = 23

    By wrapping the equation 9 * 2 in parentheses, we force it to be calculated first, giving a different result. Even though you don't deserve it, here it is in code:


    #!/usr/bin/perl

    $complex = (9*2) - (2*9) + (180/10) * 10 * (2 * 5) / 100;

    print $complex;

    This gives us the result:

      18

    Exponentially Yours

    The exponential operator (**) allows you to get the power of a number. For instance, 5**100 is 5 to the hundredth power, or 7.88860905221012e+069. Or simply put, some ridiculously crazy number. Something simpler to comprehend might be 3**3, which is 3 to the third power or 3 * 3 * 3 (which of course equals 27). Here it is in code:


    #!/usr/bin/perl

    $power = 0**10;

    $powera = 1**10;

    $powerb = 2**10;

    $powerc = 3**10;

    $powerd = 4**10;

    print $power . "\t" ;

    print $powera . "\t";

    print $powerb. "\t" ;

    print $powerc. "\t" ;

    print $powerd. "\t" ;

    And the result is...

      0 1 1024 59049 1048576



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

       

    PERL ARTICLES

    - More Perl Bits
    - Perl, Bit by Bit
    - Basic Charting with Perl
    - Using Getopt::Long: More Command Line Option...
    - Command Line Options in Perl: Using Getopt::...
    - Web Access with LWP
    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek