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

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



> 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?
>


Why don't you write a simple script that emulates a command-line.
Something like:

#----------------------------------------------------------
while($Command ne "exit")  {        ## Repeat until user types "exit"
    print "\$ ";
    $Command = <STDIN>;      ## Get Input
    chomp $Command;

                 ## Parce Script and Arguments, setting @ARGV
    ($Script, @ARGV) = $Command =~ /([^ ]+)/g;

                             ##Get the file
    $RunThis = "";
    open(SCRIPT, "<$Script");   while(<SCRIPT>) { $RunThis .= $_ };

    eval $RunThis;           ## Run it
}
#----------------------------------------------------------


Put it in the same folder as generateReport.pl, and you should be in
good shape, as long as your scripts dont have anything Unix-specific
(including paths).  If you do, you can adapt these parts of your code to
run on Mac and Unix by testing the $^O variable.

#----------------------------------------------------------
if($^O eq "MacOS") {
    $PathContains = ":";
}else{
  $PathContains = "/";
}
#----------------------------------------------------------





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