iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Perl with cheese...
    143,018

    iLoveTheCode.com
    Perl > Perl Tutorials How To Easy > OPEN and WRITE a Data File in Perl

    OPEN and WRITE a Data File in Perl



    The single right arrow means overwrite the contents of the file places.txt

    open(DA, ">places.txt");
    print DA "I see London\n";
    close(DA);

    -The word DA is called a Filehandle. Always use ALL CAPS for filehandles. The DA could be pretty much anything you like except STDIN and STDOUT, which are reserved for other things.
    -Use full or relative path if places.txt is in different directory.

    The two right arrows mean add to the contents of the file places.txt

    open(DA, ">>places.txt");
    print DA "I see London\n";
    close(DA);


    NOTES:
    -For our Copy and Paste Code, I created a directory named citydata. This directory will likely have to be chmoded 777 to be written to.
    -The two vertical bars mean "or". In this instance, open file "or" print "Can't Open blablabla".
    -the "\n" adds a UNIX line return to the end of our sentence.

    Copy and Paste Perl Code:

    #!/usr/bin/perl

    print "Content-type:text/html\n\n";

    open(DA, ">citydata/places.txt") || print "Can't Open File. Try chmod 777 citydata directory<br><br>";
    print DA "I see London\n";
    close(DA);

    open(DA, "<citydata/places.txt");
    @da=<DA>;
    close(DA);

    print @da;

    exit;

    Open and Write to a Data File in Perl - See in Action (new window)


    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Matching with a Regular Expression, REGEX, in Perl
    Next Article: Renaming a File with Perl's RENAME Function





    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    New Perspectives on HTML...New Perspectives on HTML, XHTML, and...

    Patrick Carey

    New $69.26

    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99


    Of Interest:
  • Create a Subroutine in Perl
  • Getting Server Time in Perl
  • Passing a Variable or Value to a Subroutine in Perl
  • Use chmod in Perl
  • Use onLoad in Body Tag with Javascript
  • Match with a Regular Expression, REGEX, in Javascript
  • Make Text Blink Using Javascript
  • Passing an Argument or Variable to a Javascript
  • HTML Body Tag
  • Make Text Bold Using HTML
  • Make a New Paragraph Using HTML
  • HTML Superscript Text

  • More Articles:
  • Create a Subroutine in Perl
  • Redirect to a Different URL in Perl
  • Getting What is Matched in Perl
  • onClick Javascript
  • Change a Form Field with Javascript
  • Environmental Variables Available in Javascript using Navigator Object
  • Use onLoad in Body Tag with Javascript
  • Substitute in Javascript Using replace Method
  • HTML Background
  • Make a New Paragraph Using HTML
  • HTML Body Tag
  • HTML Title Tag

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    439,783
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:16 EDT