funkfactorus
Programmer
Hi all! Noob to perl here...
I have widget with X sections, each having Y dimensions. The amount of sections is dynamic, but amount of dimensions per section is static (let's say it is always 3 dimensions per section).
I have a scalar which is a comma-delimited string of numeric values representing values for all the combinations of section and dimensions, such as:
$data = "value1,value2,value4,value5,value6,value7, ..."
So the first three values belong to first section, values 4-6 belong to second section and so on.
I also have an array with names of the sections.
@sections= ("A, B, C, D");
I also have names for the dimenstions:
@dim_names = ("Xpos", "Ypos", "Zpos")'
I want to build a hash such as:
%section_data = qw/
"A-Xpos" => "value1",
"A-Ypos" => "value2",
"A-Zpos" => "value3",
"B-Xpos" => "value4",
"B-Ypos" => "value5",
...
...
/;
I'm not really sure how to tackle this. I was thinking of maybe doing nested loops for section names and dimension names, chipping away at @data using somehting like /\G.,?/g, but that seem a bit awkward and I would love to know a better way. Any help is much appreciated. Abstract code samples would be great! Thanks in advance!
I have widget with X sections, each having Y dimensions. The amount of sections is dynamic, but amount of dimensions per section is static (let's say it is always 3 dimensions per section).
I have a scalar which is a comma-delimited string of numeric values representing values for all the combinations of section and dimensions, such as:
$data = "value1,value2,value4,value5,value6,value7, ..."
So the first three values belong to first section, values 4-6 belong to second section and so on.
I also have an array with names of the sections.
@sections= ("A, B, C, D");
I also have names for the dimenstions:
@dim_names = ("Xpos", "Ypos", "Zpos")'
I want to build a hash such as:
%section_data = qw/
"A-Xpos" => "value1",
"A-Ypos" => "value2",
"A-Zpos" => "value3",
"B-Xpos" => "value4",
"B-Ypos" => "value5",
...
...
/;
I'm not really sure how to tackle this. I was thinking of maybe doing nested loops for section names and dimension names, chipping away at @data using somehting like /\G.,?/g, but that seem a bit awkward and I would love to know a better way. Any help is much appreciated. Abstract code samples would be great! Thanks in advance!