Flame has asked for the wisdom of the Perl Monks concerning the following question:

This is really strange, but I'm not quite sure how to explain it. I have a project (full source available at Flame's scratchpad *the school project listing*) and I use Apache::Request on it. Now I've been using Apache::Request's param method to get the current params, however I'm running into a bit of difficulty now that I am using one paramater with multiple values. Now around line 113 I convert the params to a hash using the following:

my %ARGS; { #Localize @temp since I won't need it later my @temp = $state->{'r'}->param(); foreach (@temp){ $ARGS{$_} = $state->{'r'}->param($_); } }

This has worked up till now, when I needed that second value. I attempted, where I needed it (roughly line 985, the sub browse), to use the following:

my @schedules = $state->{'r'}->param('browseselect'); return qq~<tr><td>~.Dumper(@schedules).qq~</td></tr>~;

As a simple test to see that it could get these values out, however when I attempt this, the apache thread seems to lock up. As a further experement I changed the initial setup of the %ARGS hash to this:

my %ARGS; { my @temp = $state->{'r'}->param(); foreach (@temp){ $ARGS{$_} = (scalar(@{ [$state->{'r'}->param($_)] }) > 1 ? [$ +state->{'r'}->param($_)] : $state->{'r'}->param($_)) ; } }

After this change, suddenly everything is working and yielding the expected results. So I now find myself wondering why the difference. I admit this is poorly described here, I'm not sure I fully understand my question myself, but I'm really confused here. Thanks for any assistance you can give.





My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Replies are listed 'Best First'.
Re: Apache::Request and param($x) infinite loop?
by Lhamo Latso (Scribe) on Mar 19, 2003 at 06:35 UTC
    I may be naive here, but I see that your working solution is accessing the return from Apache::Request::param() as an anonymous array reference. If the request module is going to return multiple values, it would need to be an array/list?!?

    So, your code [$state->{'r'}->param($_)] looks to be the correct access method. The question is, why not check to see if the returned value is a ref?

      That's one of the oddities here. You see, until now none of my fields had to have multiple values, so the original solution was fine, and since I had only one field with mulitple values, I concluded that I could ignore its entry in the ARGS hash and simply re-request it, this time treating it as an array, which I believe could be done in using CGI, which Apache::Request claims to mimic with the differences stated in the docs. For some reason when I re-request it though after treating it like a scalar once, it get caught up in what seems to be an infinite loop (I haven't been able to locate the source so I can't say for sure, all I know is I need to restart apache to get it to respond again.)

      While my improvised solution would work, I don't want to re-write the rest of the code to adapt to only one section of code requiring multiple values, so I'm kinda stuck. (I'm concerned that someone will intentionally pass multiple values for some of the other fields at some point, which, in it's current state, it will ignore the second value onward of, but under the modification would be automatically converted to an array ref.)



      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Re: Apache::Request and param($x) infinite loop?
by Flame (Deacon) on Mar 20, 2003 at 00:17 UTC

    Ok, that was stupid... just realized I misnamed the state variable as it was passed (used to writing OO, called it $self, referred to it as $state, it was only visible in the main body of the sub, not in the excerpt I used)

    /me bangs his head repeatedly against a wall and then enables warnings



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)