in reply to help with arrays

Here's a place where assigning in a list context and using array slices is neato. You could try this:

my ($rpt_name, $desname, $btch, $record) = @ARGV[0..3];

which is a compact way of doing what your code already does.

Now, as to functional matters, the first thing I noticed is that the qw() does not interpolate, so all you'll ever get are the names of your arguments in there. So that qw()won't do.

Here's a good rule to live by: when you're generating strings and then passing them to system calls, print those strings out when you're not getting the behavior you desire, at least during development. If you'd done that, you'd notice that the command you're attempting to execute isn't going to work.

As for fixing that, you're better off with something like:

# following the above my @args= ("path/to/prog", "report=$rpt_name" , ...);

for creating the @args array.

However, when you put the double-quotes around that array, you're defeating the purpose of passing an array to system, because quoting turns the array into a string. So, if you follow the above advice, you should be making the call like so:

#get rid of $retval, too, unless you need it system(@args) and die "System failed: $?\n";

HTH!

Replies are listed 'Best First'.
Re: Re: help with arrays
by Prince99 (Scribe) on Apr 20, 2001 at 23:51 UTC
    Thanks to everyone for their ideas. They took care of the problem. Unfortunately, another problem has arisen. Again I would appreciate any insight into the problem. Here is where I am so far:

    $ENV{ORACLE_HOME} = '/opt/OraHome9i/6iserver'; $ENV{REPORTS60_PATH} = '$ORACLE_HOME/repordmin/templates:$ORACLE_HOME/ +tools/devd em60/demo/reports'; if(&ReadParse(\%input)){ @args= ("/opt/OraHome9i/6iserver/bin/rwcli60", "report=$input{rpt}" , + "userid=rep_user/sinclair\@pmi", "server=rep60_kodiac", "destype=pri +nter", "desname=$input{desname}", "btch=$input{btch}", "subbtch=0", " +record=$input{record}"); &ProcessForm;} else{ die;} } sub ProcessForm { $retval = system("@args"); die "system failed: $?" unless $retval == 0;

    The problem is thus: If I call this script "test2.pl" from the command line and pass it parameters it works fine. EX.test2.pl rpt=report.rdf desname=printername btch=50 record=0
    Now if I call it from an html page as a url. EX.http://blah/blah/test2.pl?rpt=report.rdf&desname=printername&btch=50&record=0 it gives me an error and $retval=256. I don't know why it works from the command line and prints the report, but from the html page as url it doesn't. Please help a confused novice.

    Prince99

    Too Much is never enough...
      It is not a user issue, is it? A lot of systems run as user nobody or apache, and maye they don't have access to the program?
      Just a shot
                      - Ant
        Good thought, but not the issue apparently. The rights were a little off, but changing them did not fix it. The error_log says:
        malformed header from script. Bad header=bwcinvoice.rdf: /blah/blah/blah/test2.pl
        I wish i could figure this out. The part that still gets me is it runs from the command line.
        Prince99

        Too Much is never enough...