![]() |
PERL Opening Files![]() ![]() ![]() ![]() ![]()
The open() function is used to open a file and create a connection to it called a file handle. The basic open() function call looks like this:
To Open a File for Input
$INPUT_FILE="fixed.dat";
This program displays all the lines in the fixed.dat
It is considered good programming practice to close any connections that are made with the open() function as soon as possible. While not 5trictly needed, it does ensure that all temporary buffers and caches are written to the hard disk in case of a power failure or other catastrophic failure. The open() function has many variations to let you access files in different ways.
The Different Ways to Open a File
open(FILE_HANDLE); - Opens the file named in $FILE_HANDLE and connect to it using FILE HANDLE as the file handle. The file will be opened for input only.
open(FILE_HANDLE,
FILENAME.EXT); - Opens the file called FILENAME.EXTfor input using FILE HA.NDLE as the file handle.
open(FILE_HANDLE,
+
open(FILE_HANDLE, ); - Opens standard input.
open (F I LE_HANDLE, >>FILENAME.EXT);
- Opens FILENAME.EXT for appending using FILE HANDLE as the file handle.
open(FILE_HANDLE,
+
open (FI LE HAND LE,
+>>FILENAME.EXT); - Opens FILENAME.EXT for both input and output using FILE HANDLE as the file handle.
open(FILE_HANDLE, IPROGRAM) - Sends the output printed to FILE HANDLE to another program.
open(FILE_HANDLE,
PROGRAM I) - Reads the output from another program using FILE HANDLE.
|
|
PERL Perl Program Data Types Types of Variables Operator Types Functions String Functions Array Functions Expressions Statement Blocks The if Statement Unless Statement While Loops Until Loop For Loop Foreach Loop Jump Keywords Subroutines Perl References Die Function Exit Function Localtime Function Standard Files File Test Operators File Functions Opening Files Reading into Hash Printing Revisited Globbing Splitting a Record into Fields Perl's Special Variables Regular Expression Simple True-False Searches Inexact Matches in Regular Expressions Matching Any Character Characters with Class Special Locations Quantifiers Greedy Matching Modifiers Localtime Function Subsituations Letter for Letter Translations Generating A Simple Report Defining a Report Template Specifying the Picture Line Specifying the Argument Line Adding a Header Writing the ReportDomain Names Home Importance of a domain name How does a web domain name work? Domain name syntax Choosing a domain name Domain Transfer Domain Parking IP AddressWeb Design HTML DHTML XML JAVASCRIPT VBSCRIPT PHOTOSHOPWeb Hosting Web Server Web Server Software Microsoft Internet Information Server Web hosting ISP Shared web hosting Virtual web hosting Dedicated web hosting Web hosting colocation Managed web hostingE Commerce Principles of E-Commerce E-Banking Electronic Payment System E-Security Credit Cards Smart Cards
The Mailbox POP Server SMTP Server IMAP Protocol |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |