
Need Help with putting Hashes in a two-dimensional array
[posted & mailed]
Quote:
> I'd llike to split that into a twodimensional array. Each cell should be
> a hash. I tried the following (which is not even part of the solution)
> ---
Since your data is actually started by '&BASKETZEILE1=',
'&BASKETZEILE2=', etc. I have modified the regex to include the numbers
and '='.
Quote:
> for ($i=0; $i <= $#basket_rows; $i++) {
> ($basket_rows[$i]) = split (/&&/, $basket_rows[$i]);
> }
No need for a C-style for loop here. See below.
Quote:
> ---
> This does not work. I want to access the data with two methods somehow
> like this:
> ---
> $v1 = $basket_rows[1]{'BZ_STATUS'}; # only the value of this key
> $v2 = $basket_rows[1][2]; # the entire key=value pair
> ---
You will not be able to access your data in both of these ways from the
same variable. The first implies a hash reference stored in
$basket_rows[1], the second an array ref stored in $basket_rows[1]. You
can only store one reference in there. If you want to store both a
hashref and an arrayref in $basket_rows[1] then you will have to store
them in an intermediate aggregate and store a reference to that in
$basket_rows[1].
I am using an anonymous hash as the intermediate aggregate here:
$row = {
};
}
Quote:
> Please, can anybody MAILl me the correct splitting code and the correct
> referencing for accessing or printing the values of the name=value
> paris?
They're accessed as above, but with the extra level in between. And
there's no need to shout. A lot of courtesy copies are sent from clpm
to those with valid email addresses.
$v1 = $basket_rows[1]{Hash}{'BZ_STATUS'};
# only the value of this key
$v2 = $basket_rows[1]{Array}[2];
# the entire key=value pair
The whole thing can be printed quite easily with the right module.
use Data::Dumper;
--
Rick Delaney