SunQuest
 
       Perl
  Home arrow Perl arrow Page 4 - 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Perl: More on Data Types and Operators - Incremental/ Decremental


    (Page 4 of 5 )



    Symbol

    What it Does

    ++

    Adds 1

    --

    Subtracts 1

    If you want to add or subtract 1 from your value, you can use the incremental/decremental operators. Observe the code below:


    $pay_rate = 20;

    $pay_rate++;

    This would set your pay rate to 21. If you had used -- it would have lowered it to 19. Another thing to consider is the placement of your ++ symbol. Since it is after the variable, you use it differently from the way you'd use it if it was before the variable. Look at these two examples:


    $pay_rate = 20;

    $total_pay_rate = ++$pay_rate + 80;

    The above code would result in the pay rate being: 101. This is because the operator adds to the $pay_rate variable prior to the calculation. If we wrote it this way:


    $pay_rate = 20;

    $total_pay_rate = $pay_rate++ + 80;

    The result would be 100 because we increment the value of $pay_rate after the calculation. If you printed the $pay_rate and $total_pay_rate your results would be:

      $total_pay_rate: 100

      $pay_rate: 21

    Adding a String


     

    Symbol

    What it Does

    .

    Concatenate a string

    .=

    Concatenate and Assign

    If we want to add a string to an existing variable you could so by concatenating it.


    $my_sentence = 'This ' . 'is ' . 'my ' . 'sentence!';

    If we printed that variable, we would get this result: This is my sentence!

    We could do the same thing to add variables to each other:


    $first_name = 'James ';

    $last_name = 'Payne';

    $full_name = $first_name . $last_name;

    The $full_name variable would now contain the data: James Payne.

    Comparing Strings


     

    Symbol

    What it Does

    eq

    Equal to

    ne

    Not Equal to

    gt

    Greater than

    lt

    Less than

    ge

    Equal to or Greater Than

    le

    Equal to or Less Than

    In addition to adding strings to one another, you can compare them to each other as well. The easiest of this group of operators is the eq operator. It says, literally, this string = that string. The other operators work in this manner: lowercase letters are greater than uppercase letters, and a is greater than b (b is greater than c, etc).

    Here it is in code form:


    $name_one = 'James';

    $name_two = 'Johnny';

    if ($name_one gt $name_two)

    {

    print “James is greater than Johnny!”;

    }

    That code tells the program that if James is greater than Johnny (and it is), print this sentence.

    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

    - 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
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI





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