Perl
  Home arrow Perl arrow Page 5 - Perl: Appending and Writing to Files
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: Appending and Writing to Files
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2007-11-14

    Table of Contents:
  • Perl: Appending and Writing to Files
  • Writing to Files
  • Overwriting Without Deleting Everything
  • How to Delete a File
  • More Ways to Test Files

  • 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: Appending and Writing to Files - More Ways to Test Files


    (Page 5 of 5 )

    There are also ways to test if a file is read, writable, or executable:


    $my_file="superhero.txt";

    if (-r $my_file)

    {

    #whatever you want to occur if the file is readable

    }


    $my_file="superhero.txt";

    if (-w $my_file)

    {

    #whatever you want to occur if the file is writable

    }


    $my_file="superhero.txt";

    if (-x $my_file)

    {

    #whatever you want to occur if the file is executable

    }

    And lastly, if you want to test more than one you can use the OR (||), and AND (&&) (ow my brains!) operators.


    $my_file="superhero.txt";

    if ( (-e $my_file) && (-w $my_file) )

    {

    #whatever you want to occur if the file exists and is writable

    }

    Here is a table for a quick reference:

     

    File Checks

    What it Does

    -e

    Checks to see if the file exists

    -z

    Checks to see if a file size is zero

    -s

    Checks to see if a file size is not zero

    -r

    Checks to see if a file is readable

    -w

    Checks to see if a file is writable

    -x

    Checks to see if a file is executable

    -T

    Checks to see if a file is a text file

    -B

    Checks to see if a file is a binary file

    &&, ||

    And and OR Operators used to check if one criteria or another is true, or if this criteria AND that criteria are true

    All right folks. That's it for this section covering Files. In the next series we will cover how to work with Directories and possibly forms, time permitting.

    So swing by often.

    Till then...


    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.

       · > we must first escape using the backslash(/).Do you mean '\' ? -pamag
       · Hey thanks for catching that pamag; I did indeed intend for that to read:...
     

       

    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





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