| Contents | Perl File open operation | |||||||||||||||||||||||||||||||||||
|
|
Perl - File OpenFiles are opened using the open and sysopen function. Nothing fancy here at all. Either function may be passed up to 4 arguments, the first is always the file handle discussed earlier, then our file name also known as a URL or filepath, flags, and finally any permissions to be granted to this file. When opening files as a programmer, there will generally be one of three goals in mind, file creation, appending files, or trunicating files.
PERL - Open a FileThe following example will open a previously saved HTML document. PERL Code:#!/usr/bin/perl print "content-type: text/html \n\n"; #The header $FH = "filehandle"; $FilePath = "myhtml.html"; open(FH, $FilePath, permissions); or sysopen(FH, $FileName, permission); Files with special characters or unusual names are best opened by first declaring the URL as a variable. This method removes any confusion that might occur as PERL tries to interpret the code. Tildas in filenames however require a brief character substitution step before they can be placed into your open statements. PERL - File PermissionsFile permissions are crucial to file security and function. For instance, in order to function, a PERL file (.pl) must have executable file permissions in order to function on your web server. Also, you may not want all of your HTML files to be set to allow others to write to them or over them. Here's a listing of what to pass to the open function when working with file handles. Shorthand Flags:
O_ Flags:
PERL Code:#!/usr/bin/perl print "content-type: text/html \n\n"; #The header use Fcntl; #The Module sysopen (HTML, '/home/html/myhtml.html', O_RDWR|O_EXCL|O_CREAT, 0755); sysopen (HTML, >myhtml.html'); Want Some more information
and Video ???
|