in reply to passing argv by reference

References in perl are a bit different from C or other languages.

What you have passed is like a scalar with the reference to an array; so the ways to retrieve it are:

sub spawn_proc_prog { my ($r, $command, $argv) = @_; # to access the elements of $argv you do my $first = $argv->[0]; my $second = $argv->[1]; # or my @argv = @{$argv}; # and there's a lot more..

Update: try perldoc perlref for more information about references in perl.


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Re: passing argv by reference
by Anonymous Monk on Jun 09, 2003 at 18:01 UTC
    I seem to have asked the question incorrectly. spawn_proc_prog will spawn (like the "system" call) the program specified in $command and send it arguments in the argv array. What I want to do is read the content of the argv array in the program that receives it (the one in $command), and $r is the apache request object...

    My usage looks something like :

    $command = "foo.pl";
    @args = qw(1 2 3 4 5);
    spawn_proc_prog($r, $command, \@argv);


    Now I want to be able to read the argv array in foo.pl. I get the referent, but it arrives as an empty array...

    Thanks
    - BGa
      Since it's being handled as a command, did you look in @ARGV of foo.pl?

      This is reinforced by the module doc that says:
      The third optional argument is a reference to an array which if passed becomes ARGV to the spawned program.


      --Bob Niederman, http://bob-n.com
      I don't think perl automagically will allow two (or more) processes to read and write to the same memory. The solution? Look into the IPC::Shareable module. It provides routines to tie variables to Shared memory, and lock and unlock access to avoid race conditions. If I get some time I'll post sample code.