Perl
  Home arrow Perl arrow Page 5 - Perl 101 (Part 2) - Of Variables 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 101 (Part 2) - Of Variables And Operators
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      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 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

    Operator What It Means Expression Result
    == is equal to $x == $y False
    != is not equal to $x != $y True
    > is greater than $x > $y False
    < is less than $x < $y True
    >= is greater than or equal to $x >= $y False
    <= is less than or equal to $x <= $y True


    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"

    Operator What It Means Expression Result
    eq is equal to $x eq $y False
    ne is not equal to $x ne $y True


    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"

    Operator What It Means Expression Result
    gt is greater than $x gt $y True
    lt is less than $x lt $y False
    ge is greater than or equal to $x ge $y True
    le is less than or equal to $x le $y False


    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

    - 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