Perl
  Home arrow Perl arrow Page 2 - 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 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
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 - Writing to Files


    (Page 2 of 5 )

    The phrase "writing to files" is a little misleading. When I think of writing to a file, I am really thinking of appending to the file. Why they didn't just name it Overwriting Files, I will never know, because that is really what you are doing. Basically the original file is overwritten and new data is written in its place.

    Let's say we want to get rid of all the heroes in our database and add news ones to it. We do it the same way we append to a file except for this line:


    open(DAT,">$my_file") || die ("The file has died!");

    As you can see, we now only use one greater than (>) key. This tells the program that we are writing (or overwriting) data. You assign the new values the same way as before.


    $my_file="superhero.txt";

    $heroname="Batman";

    $heropower="None. He does not need them";

    $heroweakness="Slow speech and Action Bubbles";


    open(PLOT,">$my_file") || die("The File is dead!");

    print PLOT "$heroname|$heropower|$heroweaknessn";

    close(PLOT);

    If we printed this file, this would be the contents: Batman|None. He does not need them|Slow speech and Action Bubbles

    More Perl Articles
    More By James Payne


       · > 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 1 hosted by Hostway
    Stay green...Green IT