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

Two closely related questions below for the wise...

I know how to run perl scripts at the Linux command line, e.g.

$ perl -e 'foreach $arg (@ARGV) { print "$arg\n";}' 1 2 1 2

Then on Windows desktop, I can go and fiddle the registry to allow me to drag and drop folder and file icons onto the perl script icon, and their fully qualified path names are in @ARGV, which would print out as above, or I can use in the program for reading, etc.

(1) How do I this latter drag and drop on Ubuntu? And hey, Mac instructions will be great too, but I plan to look into Platypus, and that may do it.

Next, I may have screwed up something related. Under file properties for my .pl files, the File type is "Perl script", but the 'open with' is jEdit, my preferred text editor. If I try to 'customize' back to opening with perl, I can not find the perl program (I guess as a .desktop file), so I assume I need a custom command line. In windows, that would be something like:

C:\path\perl '%f' %*

if memory serves, to pass the target script name and the passed parameters.

(2) What would be the proper custom line here? Or a proper .desktop file that passes the dropped icons or passed parameters?

Thanks very much.

Replies are listed 'Best First'.
Re: Ubuntu: drag files/folders onto perl script and get their names in @ARGV
by NetWallah (Canon) on Sep 16, 2016 at 04:10 UTC
      Thank you for that reply! I will look into it. Looks on point.
Re: Ubuntu: drag files/folders onto perl script and get their names in @ARGV
by westmj (Initiate) on Sep 16, 2016 at 19:52 UTC

    Just for the curious, and those google searchers out there, I got things worked out.

    (trusty)westmj@localhost:~/GoogleDrive/perl$ cat hello_world.pl #! /usr/bin/perl print "Hello, World!\n\@ARGV:\n"; foreach $arg (@ARGV) { print "$arg\n"; } warn "Press 'Enter' or 'Return' to finish.\n"; <STDIN> (trusty)westmj@localhost:~/GoogleDrive/perl$ perl hello_world.pl 1 2 Hello, World! @ARGV: 1 2 Press 'Enter' or 'Return' to finish. (trusty)westmj@localhost:~/GoogleDrive/perl$ cat hello_world_desktop.d +esktop [Desktop Entry] Version=1.0 Name=Hello_World_desktop Comment=Execute by dropping file onto Exec=/usr/bin/perl /home/westmj/GoogleDrive/perl/hello_world.pl '%F' #Icon=/home/alex/Pictures/icon.png Terminal=true Type=Application #Categories=Application MimeType=application/vnd.ms-excel;application/vnd.openxmlformats-offic +edocument.spreadsheetml.sheet;inode/directory;text/plain;text/x-scrip +t.perl;

    Dragging two perl files onto the .desktop file works, the output in a new terminal is:

    Hello, World! @ARGV: /home/westmj/GoogleDrive/perl/modify.pl /home/westmj/GoogleDrive/perl/Open_with_NotePad-attenders.pl Press 'Enter' or 'Return' to finish.