Perl
  Home arrow Perl arrow Page 10 - Perl 101 (Part 4) - Mind Games
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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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 4) - Mind Games
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2000-06-29

    Table of Contents:
  • Perl 101 (Part 4) - Mind Games
  • Handle With Care
  • Different Strokes
  • A Little Brainwashing
  • Die! Die! Die!
  • Testing Times
  • Popguns And Pushpins
  • Shifting Things Around
  • The Real World
  • Miscellaneous Stuff

  • 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


    Perl 101 (Part 4) - Mind Games - Miscellaneous Stuff


    (Page 10 of 10 )

    The @ARGV variable
    ------------------
    Perl allows you to specify additional parameters to your program on the command line - these parameters are stored in a special array variable called @ARGV. Thus, the first parameter passed to a program on the command line would be stored in the variable $ARGV[0], the second in $ARGV[1], and so on.

    Using this information, you could re-write the very first file-test example above to use @ARGV instead of the <STDIN> variable for input:
    #!/usr/bin/perl
    if (-e $ARGV[0])
    {
    print "File exists!\n";
    }
    else
    {
    print "File does not exist!\n";
    }

    <STDIN> and other file handles
    ------------------------------
    Perl comes with a few pre-defined file handles - one of them is <STDIN>, which refers to the standard input device. Additionally, there's <STDOUT>, which refers to the default output device [usually the terminal] and <STDERR>, which is the place where all error messages go [also usually the terminal].

    Logical Operators
    -----------------

    You've probably seen the || and && constructs in the examples we've shown you over the past few lessons. We haven't explained them yet - and so we're going to rectify that right now.

    Both || and && are logical operators, commonly used in conditional expressions. The || operator indicates an OR condition, while the && operator indicates an AND condition. For example, consider this:
    if (a == 0 || a == 1)
    {
    do this!
    }

    In English, this would translate to "if a equals zero OR a equals one, do this!" But in the case of
    if (a == 0 && b == 0)
    {
    do this!
    }

    the "do this!" statement would be executed only if a equals zero AND b equals zero.

    Perl also comes with a third logical operator, the NOT operator - it's usually indicated by a prefixed exclamation mark[!]. Consider the two examples below:
    if (a)
    {
    do this!
    }

    In English, "if a exists, do this!"
    if (!a)
    {
    do this!
    }

    In English, "if a does NOT exist, do this!"

    And that's about it for this week. We'll be back in a couple of weeks with more Perl 101. Till then...stay healthy!

    This article copyright Melonfire 2000. All rights reserved.
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    PERL ARTICLES

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

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




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