File Operations in Perl



Opens the file specified for read (update not allowed)

Example of open:

open (DB,"$db") || die "Can't Open mailadd: $!\n";
while (<DB>) {
close DB;


Opens tthe file specified for write. This function destroys the existing file by writing a file of the same name


Add records to the file specified.


Before I got serious about using MYSQL to handle database accesses, I used this heavily. Safely lets you update a text file on a server. Here is an example of the type of code I was writing before I moved to MYSQL

open FH, "+</mnt/web/guide/www/lodge.txt" or die "Cannot open $file: $!";
flock FH, 2;
seek FH, 0, 0;
my @content = <FH>;
foreach $item (@content){
$file{$warray[0]} = $item;
} #foreach
if ($record ne ""){
$file{$FORM{'number'}} = $record;}
seek FH, 0, 0;
truncate $file, 0;
print FH values(%file);
close FH;

open(FILEHANDLE,”+>filename.txt”) read/write but first truncate

Return to Perl Help

[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
Advertise on Golden Ink's Georgia Network

In Association with Amazon.com