in reply to Converting a small Windows Script File to a Perl equivalent

At first I shyed away from replying with some uninformed and untested code, but seeing crazyinsomniacs short and not that accurate reply, I'll have to take a stab at this.

Update: Research before you type. Of course, crazyinsomniac was right, but his answer was a bit too short for my taste :).

Further update: Digging deeper through the Win32::OLE documentation, events now seem to have Alpha support. So maybe it is possible. I'll dig some more ... Yes - it looks like the code below could actually work ...

Please do note, that your script uses many features that I am not sure Perl can use already ... I'm also not so sure about whether my code will actually work, but it will be a pointer in a direction that offers further frustration :)

#!/usr/bin/perl -w use strict; # We'll be dealing with OLE stuff, so we need Win32::OLE use Win32::OLE qw(EVENTS); my $Test; $Test = Win32::Ole->GetActiveObject( "MMT.VideoServeAutomation.1" ); # so far so good. I'm in real doubt that Win32::OLE implements # OLE events as they aren't for the faint of heart and require # some kind of multi-threading or at least polling of a # message queue. # Reading the documentation for Win32::OLE, it clearly # states that OLE events are not supported. So crazyinsomniac # is actually quite right with his statement that it can't # be done in Perl. D'oh. # Hehe - all is not lost - Win32::OLE comes to the rescue Win32::OLE->WithEvents( $Test, \&EventHandler ); sub EventHandler { my ($Obj, $Event, @Args) = @_; print "Got event $Event\n"; # Here is some guesswork how to find out the "right" event ... if ($Event =~ /^Connected/i) { # I hate message boxes popping up ... print "Hello\n"; } elsif ($Event =~ /^DisConnected/i) { print "Goodbye\n"; } elsif ($Event =~ /DTMFTone/i ) { print "Tone :", join(" ", @Args ), "\n"; } }; # Now we got the events set up, and we only need to loop # until the user terminates our program ... # I hope that sleeping 100 ms on each turn dosen't # hit any OLE timeouts ... while (1) { sleep( 100 ); };

This is completely untested, as I'm on a Linux machine right now. Maybe it will actually work !