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.

In reply to Getting command executable of a file type. by gmpassos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.