Main
Home
Advertising
Partners
Contact Us
Updates (new)
 
Overview
What is Perl?
 
Getting Started
Install Scripts
--> Unix
--> Windows
 
Writing Code
Hello World!
--> Basic Output
--> Adv. Output
Variables
--> Scalar
--> Arrays
--> Join Arrays
File/Directory
--> Opening
--> Saving
--> Modifying
Subroutines
--> Calling
--> Feeding
Operators new
--> Arithmetic
--> Assignment
--> Accumulating
--> Adding Strings
Examples new
--> Access Counters
--> Form Parsing
 


 
Free Newsletter
JavaScripts
HTML Help
About Computing
PerlAccess is part of: The BIG Resources Network!
PERL'S
Opening Files Tutorial
(4.1)
 
written by
Jacob Wheeler
Co-Founder / Web Engineer
Big Resources Network

This will most likely be one of your most widely used functions, open. Here you will learn the basics of opening and closing a file using perl. You will also learn to howto load the contents of a file into an array for output.

The following piece of code will open the file, file.txt for input. Saving the contents of the file to an array (@file)

  1. open (FILE, ">file.txt");
  2. @file = <FILE>;
  3. close(FILE);

Want to output the whole contents of a file? Checkout the below code that utilizes the while loop:

  1. open (FILE, "file.txt");
  2. while (FILE) { print; }
  3. close(FILE);

The following will do the same thing, however using a foreach loop, outputing line by line:

  1. open (FILE, "file.txt");
  2. foreach $a (FILE) { print $a; }
  3. close(FILE);
Questions? Comments?
Visit Our Web Forums
 

ALL MATERIAL (C) BIG RESOURCES.INC
MASCOT PERL PROVIDED BY DRAWSHOP


NETWORK SITES

DESIGN:

1-Click-Clipart

Free-Clip-Images

FontFiles

FreeWebTemplates


DEVELOPMENT:
A1Javascripts
123Webmaster

FreeWareFiles

httpCITY

HTMLForums

PerlAccess
 
NETWORK
HOT SPOTS
Internet Marketing Article @ 123webmaster
Banner Rotator @ A1javascripts
Internet Answering Machine v1.0 @ FreeWareFiles
Free Business Style Templates @ FreeWebTemplates
Newest Free Fonts @ FontFiles
 
MAILING LISTS
SelectAll
Webmaster
Free Stuff
Investing
Contests
Win 98
Win NT
Shoppers
Finance
Business
Investing
Commerce
Advertising
Marketing

More Interest Lists
Email: