Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to run the following code to find handle of the window of google talk,but it throws errors.please tell me whats wrong with the following code

use Win32::GuiTest qw( FindWindowLike ); use strict; my @Mhnds = FindWindowLike( undef, “^Google Talk” ); if( !@Mhnds ){ die “Cannot find Messenger Runningn”; }else{ printf( “handle of Messenger is %xn”, $Mhnds[ 0 ] ); }

Replies are listed 'Best First'.
Re: how to find handle of a window?
by GrandFather (Saint) on Nov 04, 2011 at 06:32 UTC

    You are missing use warnings;. Your indentation is horrible. You misspell "Runningn". Oh, and you use characters that are not valid Perl syntax. Perl is fussy about the type of quote characters that you use. I'd recommend you find a better text editor than Word or whatever you are using at present so that you can use " for double quoted strings and ' for single quoted strings without having to fight the editor.

    If you replace all the “ and ” characters with " your code works fine. I'd rewrite it as:

    use strict; use warnings; use Win32::GuiTest qw( FindWindowLike ); my @Mhnds = FindWindowLike(undef, "^Google Talk") or die "Cannot find Messenger Running"; printf "handle of Messenger is %xn", $Mhnds[0];

    to make it a little more concise and clearer (at least to my eye).

    True laziness is hard work