J
Julian
Hi,
Is there a best practice to implement an "ordered hash" in Perl?
For example I need to manipulate a csv file: each line is a record with
a fixed number of fields.
Here are some solutions but I don't find them very elegant:
Solution 1:
Two arrays: the first array holds the keys, the second array holds the
values.
my @arrkeys = ("first name", "age", "food"....)
my @arrvalues = ("joe", 39, "corn flakes",...)
Solution 2:
An array of hashes:
my @orderedhash = (
{ FieldName => "first name", Value => "Joe" },
{ FieldName => "age", Value => 39 },
...
);
Solution 3:
An array to keep the order of the field, and then a hash.
my @fieldnames = ( "first name", "age", "food",...);
my %h = { "first name" => "joe", "age" => 39,...)
TIA
Is there a best practice to implement an "ordered hash" in Perl?
For example I need to manipulate a csv file: each line is a record with
a fixed number of fields.
Here are some solutions but I don't find them very elegant:
Solution 1:
Two arrays: the first array holds the keys, the second array holds the
values.
my @arrkeys = ("first name", "age", "food"....)
my @arrvalues = ("joe", 39, "corn flakes",...)
Solution 2:
An array of hashes:
my @orderedhash = (
{ FieldName => "first name", Value => "Joe" },
{ FieldName => "age", Value => 39 },
...
);
Solution 3:
An array to keep the order of the field, and then a hash.
my @fieldnames = ( "first name", "age", "food",...);
my %h = { "first name" => "joe", "age" => 39,...)
TIA