CGI.pm mystery array

R

runderwo

Using CGI.pm from perl 5.8.8.


If I have a form variable named foo[], I noticed that using
Data::Dumper to print the contents of CGI::param for that variable:
warn Dumper $query->param('foo[]');
returns:
<!-- warning: $VAR1 = 'ARRAY(0x82996a8)'; -->

You would think, ok, it's just printing the reference to an empty
array. Odd since Dumper usually recognizes references and prints
their structure, but whatever.

The really odd thing is that if the form variable actually submitted
values, I get something like this:
<!-- warning: $VAR1 = '(e-mail address removed)';
$VAR2 = '(e-mail address removed)';
$VAR3 = 'ARRAY(0x8297a98)'; -->

What in the world is the ARRAY() member in that case? It's certainly
not containing the form values, since they are members of the list
alongside it.

Even stranger is that the member is actually a string. If I try to
dereference it with @{$query->param($key)}, I get an error about using
a string as an array ref. If I assign to a list:
my @foo = $query->param($key);

then I get a list of size 1 with the string 'ARRAY(0x8297a98)' as the
first member.

I have no idea what this means. First time I ever noticed it. Does
something seem wrong here?
 
B

Brian McCauley

Using CGI.pm from perl 5.8.8.

If I have a form variable named foo[], I noticed that using
Data::Dumper to print the contents of CGI::param for that variable:
warn Dumper $query->param('foo[]');
returns:
<!-- warning: $VAR1 = 'ARRAY(0x82996a8)'; -->

You would think, ok, it's just printing the reference to an empty
array. Odd since Dumper usually recognizes references and prints
their structure, but whatever.

Why would you think "empty"? Anyhow I can see the quotes.
I have no idea what this means. First time I ever noticed it. Does
something seem wrong here?

Either you've done something wrong or found a bug in CGI.

Could you post a _minimal_ but _complete_ script please?
 
X

xhoster

Using CGI.pm from perl 5.8.8.

If I have a form variable named foo[], I noticed that using
Data::Dumper to print the contents of CGI::param for that variable:
warn Dumper $query->param('foo[]');
returns:
<!-- warning: $VAR1 = 'ARRAY(0x82996a8)'; -->

You would think, ok, it's just printing the reference to an empty
array.

What I would think is that it printing a variable, which contains a string,
which just happens to look like the string you get when you stringify an
array reference.
Odd since Dumper usually recognizes references and prints
their structure, but whatever.

Right, it does recognize references, which is why I think what you have is
not a reference, but string.
The really odd thing is that if the form variable actually submitted
values,

As opposed to what? Where did your first example come from if not from
an actually submitted form?
I get something like this:
<!-- warning: $VAR1 = '(e-mail address removed)';
$VAR2 = '(e-mail address removed)';
$VAR3 = 'ARRAY(0x8297a98)'; -->

What in the world is the ARRAY() member in that case?

Same as above. This time, param returned a list of three strings.
The last of these three string just happens to look like what a stringified
array ref looks like.
It's certainly
not containing the form values, since they are members of the list
alongside it.

I don't know what that means.
Even stranger is that the member is actually a string. If I try to
dereference it with @{$query->param($key)}, I get an error about using
a string as an array ref. If I assign to a list:
my @foo = $query->param($key);

then I get a list of size 1 with the string 'ARRAY(0x8297a98)' as the
first member.

I have no idea what this means. First time I ever noticed it. Does
something seem wrong here?

Yes. Most likely, either the person filling in the form is doing something
perverse (like typing something that likes like a stringifed arrayref into
a form field), or the script that generated the form is doing something
perverse, like setting a stringified arrayref as a default value, or as the
value of a hidden form field.

Xho
 
R

runderwo

As opposed to what? Where did your first example come from if not from
an actually submitted form?

The form was submitted with nothing selected in that said:
Same as above. This time, param returned a list of three strings.
The last of these three string just happens to look like what a stringified
array ref looks like.


I don't know what that means.

The ARRAY() is not the container of form values that CGI.pm would be
returning.
Yes. Most likely, either the person filling in the form is doing something
perverse (like typing something that likes like a stringifed arrayref into
a form field),
No

or the script that generated the form is doing something
perverse, like setting a stringified arrayref as a default value, or as the
value of a hidden form field.

It might be, but I'll post a test case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top