in reply to opening filehandle with Win32API::File seems to return scalar

FYI, on Linux, Unix and similar systems, not only does the "raw" open service return a scalar, said scalar is just an integer. Usually applications don't use the raw open (or other raw file IO services) directly. Rather they use a library that provides a "friendlier" interface for file IO.

Perl has it's own file IO layer, as well as sysopen, sysread, etc, which provide access to the raw file IO services (or a POSIX-ized, semi-raw layer on top of non-POSIX OSs like MS Windows.)

  • Comment on Re: opening filehandle with Win32API::File seems to return scalar

Replies are listed 'Best First'.
Re^2: opening filehandle with Win32API::File seems to return scalar
by Lotus1 (Vicar) on Oct 15, 2014 at 17:44 UTC

    I read the documentation for sysopen and the only thing it seems to have that open doesn't is the ability to specify the permissions of newly created files. My old Programming Perl book says to use sysopen instead of open() before using flock() but I see the example at flock uses open(). Is there something else I missed?

    In the OP I was attempting to combine two lines of example code from the module documentation that don't work as expected. The documentation says you can tie a filehandle to a win32 handle created by createFile(). I tried that and got an error message about a missing method Win32API::File::TIESCALAR. I found a method called Win32API::File::TIEHANDLE and I was surprised that it wasn't the one called. I was expecting the low level filehandle to be something more than an integer. As you can see in the OP I printed the value of the filehandle and it was an integer.

    I wasn't interested in flock since text editors can still open and wipe out the edits my application is making while it is running. I've noticed that when certain types of files are open in Excel I can't overwrite them. I'm trying to get that same low level locking on a Windows Server 2008 platform.

    ...Usually applications don't use the raw open (or other raw file IO services) directly. Rather they use a library that provides a "friendlier" interface for file IO.

    It was my understanding that Win32API::File is a Perl friendly interface to the Win32 API. Saying that people usually don't use raw open is one of those true but irrelevant statements. If raw open is what is needed then people use raw open would be my guess.