in reply to Win32::EventLog's clear method without filename.

I haven't used Win32::EventLog, but from your description, I think what is needed is the "bit bucket". On Windows there is a special reserved file name, "nul". This file is special. Anything written to the file called "nul" is discarded - it just goes away.

The name nul, will not appear in any directory listing as this file cannot exist. You can however open a filehandle to nul to "create it", write to it and close it. It will all look like a normal file operation except at the end of the day, a file called nul is never actually created. On Windows, case doesn't matter, NUL and nul are the same. The path doesn't matter. You can write to nul in any directory.

C:\Projects>type temp.txt #types temp.txt to stdout C:\Projects>type temp.txt >nul #no output! types temp.text into cyber +space
There are all sorts of handy uses for nul. Another example:
C:\someprog.pl 2>nul
exectues someprog.pl and the normal stdout output is thrown away. But anything written to stderr, like a warning or whatever will appear on the terminal.

In Unix, this concept is implemented via the device called null. /dev/null. Please note the spelling, and the number of letter l's! That is of course important!

Replies are listed 'Best First'.
Re^2: Win32::EventLog's clear method without filename.
by dannyd (Sexton) on Dec 24, 2010 at 08:30 UTC

    Thanks a lot dasagar, im using that work around now, script is running fine :).

    Marahal, I tried what you recommended, "nul", "NUL", "NULL" and "null" - none of them work(That would be a nice solution though)

      $Event->Clear(), did you try 'C:\nul'? or some other path that you have write access to, terminating in a file that is not a file, called nul? Puzzled why that didn't work. If you just have 'nul', that would be the directory that the Perl is executing in or maybe the directory that it was launched from. Well in any event, you got a solution. Horray! nul is the right path under Windows for the bit bucket. I'm sure. Flabbergasted why it didn't work for you.