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

[MacPerl] Re: use of @ARGV in Unix/Mac



pudge@pobox.com, mac-perl@iis.ee.ethz.ch, xah@best.com
Subj:	Re: [MacPerl] use of @ARGV in Unix/Mac

Chris Nandor wrote:

> At 20.53 1998.04.25, Xah Lee wrote:
> >Suppose I have a script "generateReport.pl" that takes in a date as
> >argument and prints to STDOUT. e.g.
> >
> >[unix prompt]$ generateReport.pl 19980304
> >
> >Is it possbile to run this script on a mac without modifying it?
> >
> >Basically I'm writing scripts for unix, but need to code or test them on
> >my mac.
> >
> >Thanks in advance.
> 
> Vicki came up with a good way that we worked out that does something like this:
> 
> 
> @ARGV = MacPerl::Ask('ARGV?') if ($^O eq 'MacOS' && $MacPerl::Version !~ /MPW/);
> 
> 
> This will, if running under MacPerl and not under the MPW tool, open a
> dialog box asking you for the arguments.  It does require a slight
> modification of the script you are using, but not a drastic one, and it
> will continue to work just fine under any other platform.

unfortunately adding that single line results in a warning spewed out
under -w:

  % cat mactest
  #!/usr/local/bin/perl -w

  @ARGV = MacPerl::Ask('ARGV?') if ($^O eq 'MacOS' && $MacPerl::Version !~ /MPW/);

  print "hello, ARGV = ",join("\n",@ARGV,"");

  % perl -w mactest foo bar
  Name "MacPerl::Version" used only once: possible typo at mactest line 3.
  hello, ARGV = foo
  bar

You could get around that in either of two ways, the straightforward:

  % cat mactest
  #!/usr/local/bin/perl -w

  $MacPerl::Version = $MacPerl::Version;

  @ARGV = MacPerl::Ask('ARGV?') if ($^O eq 'MacOS' && $MacPerl::Version !~ /MPW/);

  print "hello, ARGV = ",join("\n",@ARGV,"");

or with the vars pragma:

  % cat mactest
  #!/usr/local/bin/perl -w

  package MacPerl;
  use vars qw($Version);

  package main;
  @ARGV = MacPerl::Ask('ARGV?') if ($^O eq 'MacOS' && $MacPerl::Version !~ /MPW/);

  print "hello, ARGV = ",join("\n",@ARGV,"");


either of which results in:

  % perl -w mactest foo bar
  hello, ARGV = foo
  bar

Peter Prymmer
pvhp@forte.com


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