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  
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: More on Data Types and Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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: 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
     

       

    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 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek