tchrist@convex.COM (Tom Christiansen) (02/25/91)
From the keyboard of brad@SSD.CSD.HARRIS.COM (Brad Appleton):
:
:This seems straightforward enough but I am unsure of a few things:
:
: 1) I would LIKE (meaning I "wish") to pass an array, and a string
: to my function (not just an array where the first/last element
: happens to be my string). Am I out of luck here? I suppose I
: could just have the string as the last argument in my parameter
: list and use some form of shift and $#_ to get the last arg.
I usually just let the first argument be the string:
&some_function($str, @array);
sub some_function {
local($x, @a) = @_);
....
}
You can also use pass by *reference to keep the array separate:
&some_function($str, *array);
sub some_function {
local($x, *a) = @_);
and then use @a freely.
:
: 2) How do I directly evaluate the output of a program that I have
: executed? My output should only be evaluated if the program
: returns a 0 status. It would be nice if I did not have to
: explicitly use any temporary files (some thing like the shell
: equivalent of: ' eval "`prog`" ' would be great)!
Normally,
eval `prog`;
would suffice, but you said to run it only if your program returns a
0 exit status. So you can do this:
$prog = `prog`;
eval $prog unless $?;
: 3) Is it possible to pass dash-options to my perl-script (and
: hence to my function) via ARGV? What limitations are there?
I'm not really sure what you mean here -- it's certainly easy to process
dash-options from ARGV. I don't know of any limitations except for those
imposed on your execs by the O/S. But why bother with an exec?? Is this
a perl script called by other perl scripts? If so, you probably just want
to use a do or require, not a whole nother exec to get it. Could you
show some example uses of your parseargs function? Is it anything like:
#!/usr/bin/perl
#
# some user program
$USAGE = "blah blah blah\n";
...
require 'parseargs.pl';
&parseargs(<<EO_OPTION_STRING) || die $USAGE;
here we write your
long parse arg option
description
EO_OPTION_STRING
I think it would work out better if you didn't even consider calling
outside your program to do this: then there would be no eval to be
considering.
But maybe I don't understand what you're actually doing here.
--tom
--
"UNIX was not designed to stop you from doing stupid things, because
that would also stop you from doing clever things." -- Doug Gwyn
Tom Christiansen tchrist@convex.com convex!tchrist