Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!convex!tchrist From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: executing output from a command Message-ID: <1991Feb24.233854.10400@convex.com> Date: 24 Feb 91 23:38:54 GMT References: <2431@travis.csd.harris.com> Sender: tchrist@convex.com (Tom Christiansen) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 84 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(<