SPUG: odd array ref issue

John Subaykan john.spug at subaykan.com
Thu Jan 26 10:49:15 PST 2006


Looks like cgi does return a hash that stringifies its values:
 

use strict;
use warnings;
 
use Data::Dumper;
 
use CGI;
 
my $q = new CGI; 
 
my $params = $q->Vars;
 
my $tmp = [ '102', '104' ];
 
$params->{all} = 1;
$params->{view} = "something";
 
$params->{donor_pk} = $tmp;
 
print Dumper $params;
 
 
 
You get:
 
 
 
$VAR1 = {
          'all' => '1',
          'view' => 'something',
          'donor_pk' => 'ARRAY(0x81a850c)'
        };

 
some relevant detail at: http://search.cpan.org/dist/CGI.pm/CGI.pm  scroll down to "Fetching the parameter list as a hash"
 
- John Subaykan
 
 
 
 
----- Original Message ----- 
From: mike 
To: John Subaykan 
Sent: Thursday, January 26, 2006 10:30 AM
Subject: Re: odd array ref issue


Hm. Does data dumper indicate if a hash is tied to a class? 

anyway, I create a new hash and it is not stringified in the data dump. 
a
I created $params from Vars in cgi.pm (does vars return a tied hash?). i was trying to frob some more data into the POST before processing it.. 

I can do this another way but this ghetto style approach is usually worth a shot



On 1/26/06, John Subaykan wrote: 
Is your $params hashref tied to a class that stringifies values at assignment with its STORE method?  How are you creating $params?
 
----- Original Message ----- 
From: mike 
To: members at seattleperl.org 
Sent: Thursday, January 26, 2006 10:14 AM
Subject: SPUG: odd array ref issue


I've totally been pulling my hair out over this and I'm probably missing something stupid here but I figured the SPUG eyes would notice it immediately



I have an array ref in $tmp, here is the Data::Dumpage

Thu Jan 26 10:00:40 2006 tmp: $VAR1 = [
          '102',
          '104'
        ];

then I put that into my $params hashref

    $params->{donor_pk} = $tmp;

then I Data::Dump the $params hashref 

Thu Jan 26 10:00:40 2006 params: $VAR1 = {
          'all' => '1',
          'Submit' => '1',
          'view' => 'donors',
          'donor_pk' => 'ARRAY(0x60234)'
        };

notice the dumper does not traverse into that array, which it usually does with other hashrefs and objects i've created. 
the ref() function also does not return ARRAY anymore after I stick it into that hash. furthermore, that hash goes into another hash which is obviously not going to do much for me either. 


this is something i do rather frequently but do not think i've seen this issue before. 




More information about the spug-list mailing list