Rork.nl - Articles
HOWTO: Associate extensions with your perl script
Did you ever thought how cool it could be if you can start you perl-script by double clicking a target file in explorer? Well I did, and with a little help I found a solution1. I use textedit as an example.
First you have to pick the filename from the commandline using @ARGV, and send it to the subroutine which loads the file. Here I use a simple algorithm that concatenates all commandline arguments to one filename as filenames may use whitespace. Alternate algorithms can support multiple files and comcattenate strings within double quotes. Also it's possible to use the Getopt::Long module.
if ($ARGV[0]) { load("foo", join "", @ARGV); }
Then you have to associate the extension with your perl script.
  1. Go to: Explorer > Tools > Folder Options > File Types
  2. Select the filetype which you want your script to associate with, in this example ".txt"
    If the extension is not in the list make a new one.
  3. Click advanced and edit or create the "open"action.
    If you'd rather like to open a filetype with a certain program but create an alternative which opens it with your script you can make a new action like "edit". I did this with HTML files.
  4. Set the application used to perform action to: <Perl location> <Script location> "%1"
    In this example it reads: c:/perl/bin/perl.exe d:/perl/textedit/textedit.pl "%1"
No shell
If you use Win32::Progress to open Perl/Tk programs without showing the DOS shell it's also possible to use this. I use a script named 'shortcut.pl' To do this.
Change the application to c:/perl/bin/perl.exe -w d:/perl/textedit/shortcut.pl "%1";
Now you have to adapt the arguments to Win32::Process, in shortcut.pl it reads:
Win32::Process::Create($ProcessObj, "c:perl/bin/perl.exe", join('', "perl", "d:perl/textedit/textedit.pl", @ARGV), 0, DETACHED_PROCESS, ".") or warn "Cannot open:" . Win32::FormatMessage(Win32::GetLastError());
If your script opens files by default it is important to fully specify the filename of these files.

1) This HOWTO is written for Windows ME, newer windows versions shouldn't be really different