J
JasonGilbertUK
Hi All,
I'm working through "Learn Perl in a weekend" and have hit issues in
the file handling section. The code below is taken from the book and is
a simple demo of opening / reading / closing a file.
Everytime I run it, it fails at line 2 when attempting to lock the
file. I have no other apps open that are accessing the file new.txt.
Can anyone tell me what the problem is.
For reference, I'm running under Windows XP Professional, with Admin
privilages and am using ActivePerl 5.8.8
open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
new.txt");
flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");
$onecharacter = getc (sHANDLE);
print $onecharacter
flock (sHANDLE, LOCK_UN) || die("Cannot unlock new.txt");
close (sHANDLE) || die ("Cannot close new.txt");
print "Press <ENTER> to continue...";
<>
Output from the program below, together with directory listing of the
file I'm trying to open.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
c:\perl\eg\weekend>files.pl
Cannot lock new.txt at c:\perl\eg\weekend\files.pl line 5.
c:\perl\eg\weekend>dir n*.txt
Volume in drive C has no label.
Volume Serial Number is BCB0-E820
Directory of c:\perl\eg\weekend
14/11/2006 16:41 11 namesfile.txt
14/11/2006 17:05 40 new.txt
2 File(s) 51 bytes
0 Dir(s) 23,670,530,048 bytes free
c:\perl\eg\weekend>attrib new.txt
C:\perl\eg\weekend\new.txt
c:\perl\eg\weekend>
I'm working through "Learn Perl in a weekend" and have hit issues in
the file handling section. The code below is taken from the book and is
a simple demo of opening / reading / closing a file.
Everytime I run it, it fails at line 2 when attempting to lock the
file. I have no other apps open that are accessing the file new.txt.
Can anyone tell me what the problem is.
For reference, I'm running under Windows XP Professional, with Admin
privilages and am using ActivePerl 5.8.8
open (sHANDLE, "<c:\\perl\\eg\\weekend\\new.txt") || die ("Cannot open
new.txt");
flock (sHANDLE, LOCK_EX) || die("Cannot lock new.txt");
$onecharacter = getc (sHANDLE);
print $onecharacter
flock (sHANDLE, LOCK_UN) || die("Cannot unlock new.txt");
close (sHANDLE) || die ("Cannot close new.txt");
print "Press <ENTER> to continue...";
<>
Output from the program below, together with directory listing of the
file I'm trying to open.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
c:\perl\eg\weekend>files.pl
Cannot lock new.txt at c:\perl\eg\weekend\files.pl line 5.
c:\perl\eg\weekend>dir n*.txt
Volume in drive C has no label.
Volume Serial Number is BCB0-E820
Directory of c:\perl\eg\weekend
14/11/2006 16:41 11 namesfile.txt
14/11/2006 17:05 40 new.txt
2 File(s) 51 bytes
0 Dir(s) 23,670,530,048 bytes free
c:\perl\eg\weekend>attrib new.txt
C:\perl\eg\weekend\new.txt
c:\perl\eg\weekend>