



(40 votes)#!/usr/bin/perl # readfile.pl by detour@metalshell.com # # Read in a file and print it out. # # http://www.metalshell.com/ use strict; use Fcntl ':flock'; # contains LOCK_EX (2) and LOCK_UN (8) constants my $buffer; my $file; $file = $ARGV[0]; open(INFILE, $file); # request an exclusive lock on the file. flock(INFILE, LOCK_EX); # read in each line from the file while (<INFILE>) { # $_ is the line that <INFILE> has set. print "Line: ", $_; } # unlock the file. flock(INFILE, LOCK_UN); close(INFILE);