This will be usefull if you need to open a file with it's associated executable, or if you just want to know what it is.
use Win32 ;
my $REGISTER;
use Win32::TieRegistry (Delimiter=>"/", ArrayValues=>1, TiedRef=>\$REG
+ISTER) ;
sub get_filetype_cmd {
my ( $type ) = @_ ;
my $app = $REGISTER->{"HKEY_CLASSES_ROOT/.$type//" };
my $cmd = $REGISTER->{"HKEY_CLASSES_ROOT/$$app[0]/shell/open/command
+//" };
$cmd = $$cmd[0] ;
$cmd =~ s/"(.*?)".*/$1/s ;
$cmd =~ s/(\.exe|\.bat|\.com).*/$1/si ;
return( $cmd ) ;
}
1;
Usage:
my $exec = get_filetype_cmd('xls');
open (CMD,"| $exec file.xls") ; close (CMD) ;
Note that if you make just
open (CMD,"| file.xls") ;
on Win32 it will open Excel, but with an adicional console window if you don't have a console APP. But if you want, for example, create a new process (that doesn't open a console), you really need the executable.