[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Re: dropped files



At 08:10 -0600 98/08/03, Chip Cuntz wrote:

> Could anyone provide me with a snipit of MacPerl to process a file dropped
> on a Perl application.  I think I have seen this done here on the list,
>but
> could not find the example.

TMTOWTDI, but they all start with @ARGV.

Perl puts any arguments to the script into the @ARGV array; MacPerl does
the same with files/folders dropped onto a droplet or runtime. Just walk
through @ARGV and do whatever you want to do to the various files

      for ($i = 0; $i <= $#ARGV; $i++) {
         # process $ARGV[$i]
      }
or
      foreach $file (@ARGV) {
         # process $file
      }

The mystical magical Perl idiom

     while (<>) {
       # do things to the contents of the argument files
     }

is shorthand for "Open each file in turn, reading through each, line by
line".

Then there are really simple things like:

    $myfile1 = shift @ARGV;

There's More Than One Way To Do It


MacPerl: Power and Ease has some examples of how to interactively ask for a
file if you double-click the droplet instead of dropping a file onto it.
See ch. 8  http://yggdrasil.com/~rdm/MP/215.Curious.html#06

It occurs to me that
   a) MPPE should show the above foreach loop as well
   b) MPPE should show the while(<>) shortcut as well
   c) do we need a more in-depth example of what to do with a set of
     dropped files?

---
Vicki Brown, vlb@cfcl.com        |\      _,,,---,,_
Journeyman Sourceror      ZZZzz /,`.-'`'    -.  ;-;;,_
Scripts & Philtres             |,4-  ) )-,_. ,\ (  `'-'
http://www.cfcl.com/~vlb      '---''(_/--'  `-'\_)
P.O. Box 1269 San Bruno, CA  94066

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch