See perldoc -f flock, but specifically, no you do not need the 'use' statement with the way you are calling flock, that is with the '2' instead of using one of the "symbolic" names that Fcntl:flock provides, from the aforementioned perldoc:

"OPERATION is one of LOCK_SH, LOCK_EX, or LOCK_UN, possibly combined with LOCK_NB. These constants are traditionally valued 1, 2, 8 and 4, but you can use the symbolic names if you import them from the Fcntl module, either individually, or as a group using the ’:flock’ tag."

So this really comes down to a matter of preference and readability.

Is it an error or a warning, if a warning then you can do a "no warnings" (I think) in a particular lexical scope to prevent it, if its a warning you can test $^O for MSWin32 and not perform your flock,

flock(FILEHANDLE, 2) unless ($^O eq 'MSWin32');

From perldoc perlvar:

"$^O
The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to $Config{’osname’}. See also Config and the -V command-line switch documented in perlrun.

In Windows platforms, $^O is not very helpful: since it is always "MSWin32", it doesn’t tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants."

HTH,

http://danconia.org



Rene Verharen wrote:
Hi all,

Do I always need

use Fcntl qw(:flock);

if I want to use

flock(FILEHANDLE, 2)

in my scripts ? I'm asking because some scripts I found on the web do and some other don't, although they all use flock.


Is there also a nice way to omit the "flock() unimplemented on this platform" error when testing my scripts local on a W98 platform ?
I'm using ActiveState Perl version 5.005_03



Kind regards,



Rene Verharen


Please DO NOT reply to me personally. I'll get my copy from the list.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to