Perl
  Home arrow Perl arrow Page 3 - Perl: More on Data Types and Operators
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: More on Data Types and Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-10-15

    Table of Contents:
  • Perl: More on Data Types and Operators
  • Hashes are Yummy
  • Operating the Deep Seas
  • Incremental/ Decremental
  • Comparing Numbers

  • 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: More on Data Types and Operators - Operating the Deep Seas


    (Page 3 of 5 )

    Argh! Thar she blows! The great white whale of the sea -- or, more precisely, the treasure that every Perl diver seeks. In this case, though, it's not something that goes into jewelry, it's something that adds quite a bit of power to your coding. 

    Operators in Perl (as in all programming languages) allow you to manipulate data. You've worked with operators ever since elementary school, albeit somewhat differently. 

    Just as there are different data types, there are different operators for the different kinds of data. We will go through a bunch of them. First though, how would you like to see a gigantic table full of mind-numbing data? I thought you might.

    Mathematical Operators


     

    Symbol

    What it Does

    +

    Adding

    -

    Subtracting

    *

    Multiplying

    /

    Dividing

    %

    Modulating

    **

    Exponentiating


    The above operators work just as you think they would. If I wanted to figure out my weekly salary, I could do the follow code:


    #!/usr/local/bin/perl


    $hours = 40;

    $wage = 20;

    $total_salary = $hours * $wage;

    print $total_salary

    That would give me the following result:

      800

    Operators that Assign Values


     

     

    Symbol

    What it Does

    =

    Assign Normally

    +=

    Assign and Add

    -=

    Assign and Subtract

    *=

    Assign and Multiply

    /=

    Assign and Divide

    %=

    Assign and Modulate

    **=

    Assign and Exponentiate

    In the previous tutorial we used the = symbol to assign a value to a variable. We can use it for other things as well. For instance, let's say you are the boss's son and have just received your first paycheck. It isn't enough to buy that Porsche you desperately need to compensate for certain characteristics you lack. Well, you can always change it like this:


    $pay_rate = 20;

    $pay_rate+=80;

    print $pay_rate;

    The above example would print your pay rate as being: 100. Another way of looking at it is saying you had written this code instead:


    $pay_rate = 20;

    $pay_rate=$pay_rate + 80;

    print $pay_rate;

    You can do the same sort of thing with the other operators above.

    More Perl Articles
    More By James Payne


       · Hey guys, thanks for dropping by and reading my article; I hope its helpful. Perl is...
     

       

    PERL ARTICLES

    - 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
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI





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