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  
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? 
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 - 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
     

       

    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
    Stay green...Green IT