Perl
  Home arrow Perl arrow Page 2 - Perl Conditionals
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 Conditionals
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2007-10-16

    Table of Contents:
  • Perl Conditionals
  • You Better or Else!
  • The Unless Statement
  • The While Loop

  • 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

    A high performance database engine using optimized data access for all development environments including Delphi, Visual Studio .NET, Visual Basic, Visual FoxPro. and more. Learn More

    Perl Conditionals - You Better or Else!
    (Page 2 of 4 )

    Part of being a rich, illustrious writer is bossing people around. Many times throughout the day I will berate the employees around me, sending them scurrying for cover. [Well, you can dream. --Ed.] When they don't do what I like or want, I give them an If Statement with an Else clause.


    #!/usr/bin/perl


    $do_my_bidding = 'Yes Master!';


    if ($do_my_bidding = 'Yes Master!'


    {

    print "You are a good slave. Tell your mother I will see her tonight";

    }

    else

    {

    print "You ignorant buffoon! Tell your mother I will see her on my lunch break!";


    print "Get out of my sight!";

    In the above code, if $do_my_bidding holds the value, "Yes Master!" you will get the following result:

      You are a good slave. Tell your mother I will see her tonight.

      Get out of my sight!

    If the value of $do_my_bidding held any other value, you would see this:

      You ignorant buffoon! Tell your mother I will see her on my lunch break!

      Get out of my sight!

    No matter which condition is met, the program will always print: Get out of my sight!, as it is not part of either conditional.

    Elsif

    Sometimes one Else clause is not enough. That's where Elseif comes in handy. Observe!


    #!/usr/bin/perl


    $do_my_bidding = 'Yes Master!';

    {

    print "You are a good slave. Tell your mother I will see her tonight";

    }

    elsif ($do_my_bidding = 'No')

    print "Insolent swine! Tell your mother to come right now!";

    else

    {

    print "You ignorant buffoon! Tell your mother I will see her on my lunch break!";


    print "Get out of my sight!";

    Again, with the above code, if the value of $do_my_bidding is "Yes Master!" it will result in:

      You are a good slave. Tell your mother I will see her tonight.

      Get out of my sight!

    If the value of $do_my_bidding is "No" the following would print to your screen:

      Insolent swine! Tell your mother to come right now!

      Get out of my sight!

    And finally, if the value of $do_my_bidding is anything else, it will print:

      You ignorant buffoon! Tell your mother I will see her on my lunch break!

      Get out of my sight!

    You will note two things: 1) The phrase "Get out of my sight!" is always printed as it is outside of the statements. And 2) No matter what you say, I am still going to spend some time with your mother. It's simply a matter of when.

    More Perl Articles
    More By James Payne


       · In this episode I discuss conditionals within Perl, as well as the While loop and...
     

       

    PERL ARTICLES

    - 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
    - Perl: Releasing Your Inner Textuality

     
    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 2 hosted by Hostway