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

I've been trying to figure out if there is a way to have a perl file understand that i want it to do something with a file i drop onto it. When you make a link to certain executables in Window or Linux the files will be opened by those applications. for instance drop a text file on a shortcut to emacs and emacs will open that file for editing.
I imagine as perl files are interpreted not executed that it is unlikely that this will work transparently, but is there any kind of workaround for this?
ideally some thing like this would work like:
perl script.pl "/path/to/file1" "/path/to/file2"
Why would i want to do this? Mostly as a way to keep my users away from the command line, I believe this would be easier to teach them to do than going over command line basics.

Replies are listed 'Best First'.
Re: Drag and drop to a perl source file.
by hiseldl (Priest) on Sep 09, 2002 at 15:36 UTC
    If you are using ActiveState Perl, you can create a "drop target" using the following steps:

    1. write your script and save it (for this example, I used the following code:
        #!perl -w use strict; open(OUT, ">>drop.txt") or die "Could not open drop.txt"; my $time = scalar localtime; print OUT $time,"\t"; print OUT @ARGV,"\n"; close (OUT);
      and named it drop.pl
    2. change to the directory where your script is located and use the pl2bat.bat script to "convert" your script to a .bat file. i.e. cmd> pl2bat.bat drop.pl
    3. on the desktop right click and choose new->shortcut and create a shortcut to your .bat file.

    now you can drop files on the new shortcut (.bat file) icon and it will use the full path as an argument. I tested this on my win2k box, and when I cat the drop.txt file, I get the time and the name of the full path as expected. YMMV.

    --
    hiseldl
    "Act better than you feel" --inner prophet

Re: Drag and drop to a perl source file.
by jmcnamara (Monsignor) on Sep 09, 2002 at 16:12 UTC

    On Window you can do something like this. Create a batch file like this:
    perl %1

    Create a link from the batch file to the desktop. Now if you drop a perl source file on the icon it will launch a command tool and run the program. The default is for the command tool to stay open but you can change that.

    To execute more that one file you can do some batch hackery with %1 .. %9.

    Update: Having read hiseldl's solution I realise that I was answering the wrong question. hiseldl's solution looks like the way to go.

    --
    John.

Re: Drag and drop to a perl source file.
by zentara (Cardinal) on Sep 09, 2002 at 16:21 UTC
    The X text editor Cooledit has an associated program called Coolicon which lets you setup some drag'n'drop support for linux. coolicon You could make your perl script accept input from STDIN and associate with an icon of your choosing.