shadedecho
Programmer
OK, I am only basically familiar with perl, my specialty is PHP. However, I am trying to use it (enabled by mod_perl) to configure my apache (httpd.conf) instance. I have all that part working, except I've run into a frustrating data-typing problem when trying to construct (from mysql queries, in this case) the right type of arrays/hashes/etc to pass back to the httpd.conf file.
So, rather than this being a question about the httpd.conf mod_perl configuration (from my web searching, not a particularly well known or often used feature as I am trying to do it, apparently), I just need to ask some general questions about how to construct the right data type, and then I can apply it to my code.
So, If I do this code in my httpd.conf
I get:
as the output. This particular type of output is the desired data typing.
I'm not sure what to use to refer to $temp or $temp{'blah'}. is this an array, or a hash, or a list, or something else? in PHP, I'd call this a 3-dimensional (associative) array. The first dimension is the associative key "blah", which i could add other entries like "blah2". The second dimension is numerically indexed (the two sets of { } each being an anonymous key'd item added to the "blah" item). The third dimension is another associative array, with the characters "a", "b", etc acting as the indexes, and finally the string values of "123" and so on associated with them.
In any case, the above code I provided, which creates whatever type of data this is, explicitly, I need to recreate this same type of data, but using loops and serial data adding calls, as records are returned one at a time from my DB call.
My strategy was to collect the "a", "b", and "c" items into some sort of temporary variable (perhaps called a hash, of some sort?), and then once it was completely filled, then "push"ing that temp variable onto the end of the $temp{'blah'} "array".
Secondarily, I need a way to, as I eluded to earlier, push some of those temporary variable items onto $temp{'blah2'} for instance as well. My code logic already makes all those appropriate decisions.
Here's some sample code that demonstrates how I *was* trying to do this, and being unsuccessful:
When I did this, and then did a "print Dumper $temp{'blah'};", i got as output:
Notice this data type is different in structure from the desired one in that each {'a' => '123'} item is on the $temp{'blah'} array, rather than each being grouped as one item. Essentially, it's like my data-typing errors/wrong code eliminated one of the intended dimensions.
can anyone help me get a correct set of code to create the kind of structure i want, including how to declare the temporary variables, and use them, and print them out with Dumper so I can effectively test my code?
So, rather than this being a question about the httpd.conf mod_perl configuration (from my web searching, not a particularly well known or often used feature as I am trying to do it, apparently), I just need to ask some general questions about how to construct the right data type, and then I can apply it to my code.
So, If I do this code in my httpd.conf
Code:
$temp{'blah'} = [
{
a => '123',
b => '456',
b => '789'
},
{
d => '789',
e => '456',
f => '123'
}
];
print Dumper $temp{'blah'};
I get:
Code:
$VAR1 = [
{
'a' => '123',
'b' => '456',
'c' => '789'
},
{
'd' => '789',
'e' => '456',
'f' => '123'
}
];
I'm not sure what to use to refer to $temp or $temp{'blah'}. is this an array, or a hash, or a list, or something else? in PHP, I'd call this a 3-dimensional (associative) array. The first dimension is the associative key "blah", which i could add other entries like "blah2". The second dimension is numerically indexed (the two sets of { } each being an anonymous key'd item added to the "blah" item). The third dimension is another associative array, with the characters "a", "b", etc acting as the indexes, and finally the string values of "123" and so on associated with them.
In any case, the above code I provided, which creates whatever type of data this is, explicitly, I need to recreate this same type of data, but using loops and serial data adding calls, as records are returned one at a time from my DB call.
My strategy was to collect the "a", "b", and "c" items into some sort of temporary variable (perhaps called a hash, of some sort?), and then once it was completely filled, then "push"ing that temp variable onto the end of the $temp{'blah'} "array".
Secondarily, I need a way to, as I eluded to earlier, push some of those temporary variable items onto $temp{'blah2'} for instance as well. My code logic already makes all those appropriate decisions.
Here's some sample code that demonstrates how I *was* trying to do this, and being unsuccessful:
Code:
my @temp_var;
$temp_var = {'a' => '123'};
push @temp_var, {'b' => '456'};
push @temp_var, {'c' => '789'};
push @( $temp{'blah'} }, @temp_var
When I did this, and then did a "print Dumper $temp{'blah'};", i got as output:
Code:
$VAR1 = [
{
'a' => '123'
},
{
'b' => '456'
},
{
'c' => '789'
}
];
Notice this data type is different in structure from the desired one in that each {'a' => '123'} item is on the $temp{'blah'} array, rather than each being grouped as one item. Essentially, it's like my data-typing errors/wrong code eliminated one of the intended dimensions.
can anyone help me get a correct set of code to create the kind of structure i want, including how to declare the temporary variables, and use them, and print them out with Dumper so I can effectively test my code?