Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

10.2 Opening Filehandles

Filehandles are opened using the "open" operator. When specifying a name for your filehandle the recommended syntax is to use all uppercase letters. The reason for this is to ensure that you don't inadvertently use a filehandle name that may one day become a reserved word in a future release of Perl. Whilst you don.t have to follow this convention it is wise to do so to maintain forward compatibility with future releases of Perl. It is also a convention that will make your code more readable to other Perl developers.

The syntax for the open operator is straightforward:

open FILEHANDLENAME "filename";
where FILEHANDLENAME is your choice of name for the filehandle and .filename. is the name of the file you want to open to connection to. For example:
open MYDATA, "datafile";
will create a filehandle called MYDATA assigned to the file on my filesystem called .datafile. The default is to open files for input. You can specifically specify that the filehandle is for input by specifying the "<" character in the file name - for example "<datafile". To open a file for output prefix the filename with the "<" character. Note that this will create a new file if it does not already exist and overwrite if it does:
open OUTDATA, "<datafile";
If your intention is to append data onto the end of an existing data file then prefix the filename with "<<" characters. If the file already exists the original content will be preserved and new data added to the end of the file:
open APPENDDATA, "<<datafile";



 
 
  Published under the terms of the GNU General Public License Design by Interspire