Perl
  Home arrow Perl arrow Page 5 - Perl 101 (Part 2) - Of Variables And O...
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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 101 (Part 2) - Of Variables And Operators
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2000-06-01

    Table of Contents:
  • Perl 101 (Part 2) - Of Variables And Operators
  • Q
  • 2 2 ...
  • ... Or Two Plus Two
  • Comparing Apples And Oranges
  • Decisions! Decisions!
  • Handling The Gray Areas
  • Miscellaneous Notes

  • 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 101 (Part 2) - Of Variables And Operators - Comparing Apples And Oranges
    (Page 5 of 8 )

    In addition to the various arithmetic and string operators, Perl also comes with a bunch of comparison operators, whose sole raison d'etre is to evaluate expressions and determine if they are true or false. Here's a list - you should use these operators for numeric comparisons only.

    Assume $x=4 and $y=10

    OperatorWhat It MeansExpressionResult
    ==is equal to$x == $yFalse
    !=is not equal to$x != $yTrue
    >is greater than$x > $yFalse
    <is less than$x < $yTrue
    >=is greater than or equal to$x >= $yFalse
    <=is less than or equal to$x <= $yTrue


    If, however, you're planning to compare string values, the two most commonly used operators are the equality and inequality operators, as listed below.

    Assume $x="abc", $y="xyz"

    OperatorWhat It MeansExpressionResult
    eqis equal to$x eq $yFalse
    neis not equal to$x ne $yTrue


    You can also the greater- and less-than operators for string comparison - however, keep in mind that Perl uses the ASCII values of the strings to be compared when deciding which one is greater.

    Assume $x="m", $y="M"

    OperatorWhat It MeansExpressionResult
    gtis greater than$x gt $yTrue
    ltis less than$x lt $yFalse
    geis greater than or equal to$x ge $yTrue
    leis less than or equal to$x le $yFalse


    The reason for this - the ASCII value of "m" is greater than the ASCII value of "M".

    This article copyright Melonfire 2000. All rights reserved.

    More Perl Articles
    More By Vikram Vaswani and Harish Kamath, (c) Melonfire


     

       

    PERL ARTICLES

    - 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
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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